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

Function webpack

lib/webpack.js:188–267  ·  lib/webpack.js::webpack
(options, callback)

Source from the content-addressed store, hash-verified

186 * @returns {Compiler | MultiCompiler | null} Compiler or MultiCompiler
187 */
188const webpack = (options, callback) => {
189 const create = () => {
190 const isMultiCompiler = Array.isArray(options);
191
192 if (
193 !asArray(/** @type {WebpackOptions} */ (options)).every((options) =>
194 needValidate(options) ? webpackOptionsSchemaCheck(options) : true
195 )
196 ) {
197 getValidateSchema()(
198 webpackOptionsSchema,
199 isMultiCompiler
200 ? options.map((options) => (needValidate(options) ? options : {}))
201 : needValidate(options)
202 ? options
203 : {}
204 );
205 util.deprecate(
206 () => {},
207 class="st">"webpack bug: Pre-compiled schema reports error while real schema is happy. This has performance drawbacks.",
208 class="st">"DEP_WEBPACK_PRE_COMPILED_SCHEMA_INVALID"
209 )();
210 }
211 /** @type {MultiCompiler | Compiler} */
212 let compiler;
213 /** @type {boolean | undefined} */
214 let watch = false;
215 /** @type {WatchOptions | WatchOptions[]} */
216 let watchOptions;
217 if (isMultiCompiler) {
218 /** @type {MultiCompiler} */
219 compiler = createMultiCompiler(
220 options,
221 /** @type {MultiCompilerOptions} */
222 (options)
223 );
224 watch = options.some((options) => options.watch);
225 watchOptions = options.map((options) => options.watchOptions || {});
226 } else {
227 const webpackOptions = /** @type {WebpackOptions} */ (options);
228 /** @type {Compiler} */
229 compiler = createCompiler(webpackOptions);
230 watch = webpackOptions.watch;
231 watchOptions = webpackOptions.watchOptions || {};
232 }
233 return { compiler, watch, watchOptions };
234 };
235 if (callback) {
236 try {
237 const { compiler, watch, watchOptions } = create();
238 if (watch) {
239 compiler.watch(watchOptions, callback);
240 } else {
241 compiler.run((err, stats) => {
242 compiler.close((err2) => {
243 callback(
244 err || err2,
245 /** @type {options extends WebpackOptions ? Stats : MultiStats} */

Callers

nothing calls this directly

Calls 5

createFunction · 0.70
callbackFunction · 0.50
watchMethod · 0.45
runMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected