MCPcopy
hub / github.com/webpack/webpack / compile

Function compile

test/Compiler.test.js:21–128  ·  test/Compiler.test.js::compile

* @param {string} entry entry file * @param {import("../").Configuration} options webpack options * @param {(stats: CompileStats, files: Record<string, string>, compilation: import("../").Compilation) => void} callback done callback

(entry, options, callback)

Source from the content-addressed store, hash-verified

19 * @param {(stats: CompileStats, files: Record<string, string>, compilation: import(class="st">"../").Compilation) => void} callback done callback
20 */
21 function compile(entry, options, callback) {
22 const noOutputPath = !options.output || !options.output.path;
23
24 const webpack = require(class="st">"..");
25
26 /** @type {import(class="st">"../").WebpackOptionsNormalized} */
27 const normalizedOptions =
28 webpack.config.getNormalizedWebpackOptions(options);
29 if (!normalizedOptions.mode) normalizedOptions.mode = class="st">"production";
30 normalizedOptions.entry = /** @type {import(class="st">"../").EntryNormalized} */ (
31 /** @type {unknown} */ (entry)
32 );
33 normalizedOptions.context = path.join(__dirname, class="st">"fixtures");
34 if (noOutputPath) normalizedOptions.output.path = class="st">"/";
35 normalizedOptions.output.pathinfo = true;
36 normalizedOptions.optimization = {
37 minimize: false
38 };
39 /** @type {{ mkdir: string[], writeFile: unknown[] }} */
40 const logs = {
41 mkdir: [],
42 writeFile: []
43 };
44
45 const c = webpack(
46 /** @type {import(class="st">"../").Configuration} */ (
47 /** @type {unknown} */ (normalizedOptions)
48 )
49 );
50 /** @type {Record<string, string>} */
51 const files = {};
52 c.outputFileSystem = /** @type {import(class="st">"../").OutputFileSystem} */ (
53 /** @type {unknown} */ ({
54 mkdir(
55 /** @type {string} */ path,
56 /** @type {(err: null | NodeJS.ErrnoException) => void} */ callback
57 ) {
58 logs.mkdir.push(path);
59 const err = /** @type {NodeJS.ErrnoException} */ (new Error(class="st">"error"));
60 err.code = class="st">"EEXIST";
61 callback(err);
62 },
63 writeFile(
64 /** @type {string} */ name,
65 /** @type {Buffer} */ content,
66 /** @type {() => void} */ callback
67 ) {
68 logs.writeFile.push(name, content);
69 files[name] = content.toString(class="st">"utf8");
70 callback();
71 },
72 stat(
73 /** @type {string} */ _path,
74 /** @type {(err: Error) => void} */ callback
75 ) {
76 callback(new Error(class="st">"ENOENT"));
77 }
78 })

Callers 1

Compiler.test.jsFile · 0.70

Calls 8

tapMethod · 0.80
isArrayMethod · 0.80
requireFunction · 0.70
callbackFunction · 0.70
webpackFunction · 0.50
runMethod · 0.45
toJsonMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected