MCPcopy
hub / github.com/pmmmwh/react-refresh-webpack-plugin / getCompilation

Function getCompilation

test/helpers/compilation/index.js:33–160  ·  view source on GitHub ↗

* Gets a Webpack compiler instance to test loader operations. * @param {string} subContext * @param {Object} [options] * @param {boolean | string} [options.devtool] * @param {import('../../../loader/types').ReactRefreshLoaderOptions} [options.loaderOptions] * @param {*} [options.prevSourceMap]

(subContext, options = {})

Source from the content-addressed store, hash-verified

31 * @returns {Promise<CompilationSession>}
32 */
33async function getCompilation(subContext, options = {}) {
34 const compiler = webpack({
35 mode: 'development',
36 cache: false,
37 context: path.join(CONTEXT_PATH, subContext),
38 devtool: options.devtool || false,
39 entry: {
40 [BUNDLE_FILENAME]: './index.js',
41 },
42 output: {
43 filename: '[name].js',
44 hashFunction: 'xxhash64',
45 path: OUTPUT_PATH,
46 },
47 module: {
48 rules: [
49 {
50 exclude: /node_modules/,
51 test: /\.js$/,
52 use: [
53 {
54 loader: require.resolve('@pmmmwh/react-refresh-webpack-plugin/loader'),
55 options: options.loaderOptions,
56 },
57 !!options.devtool &&
58 Object.prototype.hasOwnProperty.call(options, 'prevSourceMap') && {
59 loader: path.join(__dirname, 'fixtures/source-map-loader.js'),
60 options: {
61 sourceMap: options.prevSourceMap,
62 },
63 },
64 ].filter(Boolean),
65 },
66 ],
67 },
68 plugins: [new webpack.HotModuleReplacementPlugin()],
69 // Options below forces Webpack to:
70 // 1. Move Webpack runtime into the runtime chunk;
71 // 2. Move node_modules into the vendor chunk with a stable name.
72 optimization: {
73 runtimeChunk: 'single',
74 splitChunks: {
75 chunks: 'all',
76 name: (module, chunks, cacheGroupKey) => cacheGroupKey,
77 },
78 },
79 });
80
81 // Use an in-memory file system to prevent emitting files
82 compiler.outputFileSystem = createFsFromVolume(new Volume());
83
84 /** @type {import('memfs').IFs} */
85 const compilerOutputFs = compiler.outputFileSystem;
86 /** @type {import('webpack').Stats | undefined} */
87 let compilationStats;
88
89 await new Promise((resolve, reject) => {
90 compiler.run((error, stats) => {

Callers 2

loader.test.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…