UNPKG

15.9 kBJavaScriptView Raw
1/*
2 MIT License http://www.opensource.org/licenses/mit-license.php
3 Author Tobias Koppers @sokra
4*/
5
6"use strict";
7
8const util = require("util");
9const memoize = require("./util/memoize");
10
11/** @typedef {import("../declarations/WebpackOptions").Entry} Entry */
12/** @typedef {import("../declarations/WebpackOptions").EntryNormalized} EntryNormalized */
13/** @typedef {import("../declarations/WebpackOptions").EntryObject} EntryObject */
14/** @typedef {import("../declarations/WebpackOptions").LibraryOptions} LibraryOptions */
15/** @typedef {import("../declarations/WebpackOptions").ModuleOptions} ModuleOptions */
16/** @typedef {import("../declarations/WebpackOptions").ResolveOptions} ResolveOptions */
17/** @typedef {import("../declarations/WebpackOptions").RuleSetCondition} RuleSetCondition */
18/** @typedef {import("../declarations/WebpackOptions").RuleSetConditionAbsolute} RuleSetConditionAbsolute */
19/** @typedef {import("../declarations/WebpackOptions").RuleSetRule} RuleSetRule */
20/** @typedef {import("../declarations/WebpackOptions").RuleSetUse} RuleSetUse */
21/** @typedef {import("../declarations/WebpackOptions").RuleSetUseItem} RuleSetUseItem */
22/** @typedef {import("../declarations/WebpackOptions").WebpackOptions} Configuration */
23/** @typedef {import("../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptionsNormalized */
24/** @typedef {import("../declarations/WebpackOptions").WebpackPluginFunction} WebpackPluginFunction */
25/** @typedef {import("../declarations/WebpackOptions").WebpackPluginInstance} WebpackPluginInstance */
26/** @typedef {import("./Compilation").Asset} Asset */
27/** @typedef {import("./Compilation").AssetInfo} AssetInfo */
28/** @typedef {import("./MultiStats")} MultiStats */
29/** @typedef {import("./Parser").ParserState} ParserState */
30/** @typedef {import("./Watching")} Watching */
31/** @typedef {import("./stats/DefaultStatsFactoryPlugin").StatsAsset} StatsAsset */
32/** @typedef {import("./stats/DefaultStatsFactoryPlugin").StatsChunk} StatsChunk */
33/** @typedef {import("./stats/DefaultStatsFactoryPlugin").StatsChunkGroup} StatsChunkGroup */
34/** @typedef {import("./stats/DefaultStatsFactoryPlugin").StatsChunkOrigin} StatsChunkOrigin */
35/** @typedef {import("./stats/DefaultStatsFactoryPlugin").StatsCompilation} StatsCompilation */
36/** @typedef {import("./stats/DefaultStatsFactoryPlugin").StatsError} StatsError */
37/** @typedef {import("./stats/DefaultStatsFactoryPlugin").StatsLogging} StatsLogging */
38/** @typedef {import("./stats/DefaultStatsFactoryPlugin").StatsLoggingEntry} StatsLoggingEntry */
39/** @typedef {import("./stats/DefaultStatsFactoryPlugin").StatsModule} StatsModule */
40/** @typedef {import("./stats/DefaultStatsFactoryPlugin").StatsModuleIssuer} StatsModuleIssuer */
41/** @typedef {import("./stats/DefaultStatsFactoryPlugin").StatsModuleReason} StatsModuleReason */
42/** @typedef {import("./stats/DefaultStatsFactoryPlugin").StatsModuleTraceDependency} StatsModuleTraceDependency */
43/** @typedef {import("./stats/DefaultStatsFactoryPlugin").StatsModuleTraceItem} StatsModuleTraceItem */
44/** @typedef {import("./stats/DefaultStatsFactoryPlugin").StatsProfile} StatsProfile */
45
46/**
47 * @template {Function} T
48 * @param {function(): T} factory factory function
49 * @returns {T} function
50 */
51const lazyFunction = factory => {
52 const fac = memoize(factory);
53 const f = /** @type {any} */ (
54 (...args) => {
55 return fac()(...args);
56 }
57 );
58 return /** @type {T} */ (f);
59};
60
61/**
62 * @template A
63 * @template B
64 * @param {A} obj input a
65 * @param {B} exports input b
66 * @returns {A & B} merged
67 */
68const mergeExports = (obj, exports) => {
69 const descriptors = Object.getOwnPropertyDescriptors(exports);
70 for (const name of Object.keys(descriptors)) {
71 const descriptor = descriptors[name];
72 if (descriptor.get) {
73 const fn = descriptor.get;
74 Object.defineProperty(obj, name, {
75 configurable: false,
76 enumerable: true,
77 get: memoize(fn)
78 });
79 } else if (typeof descriptor.value === "object") {
80 Object.defineProperty(obj, name, {
81 configurable: false,
82 enumerable: true,
83 writable: false,
84 value: mergeExports({}, descriptor.value)
85 });
86 } else {
87 throw new Error(
88 "Exposed values must be either a getter or an nested object"
89 );
90 }
91 }
92 return /** @type {A & B} */ (Object.freeze(obj));
93};
94
95const fn = lazyFunction(() => require("./webpack"));
96module.exports = mergeExports(fn, {
97 get webpack() {
98 return require("./webpack");
99 },
100 get validate() {
101 const webpackOptionsSchemaCheck = require("../schemas/WebpackOptions.check.js");
102 const getRealValidate = memoize(() => {
103 const validateSchema = require("./validateSchema");
104 const webpackOptionsSchema = require("../schemas/WebpackOptions.json");
105 return options => validateSchema(webpackOptionsSchema, options);
106 });
107 return options => {
108 if (!webpackOptionsSchemaCheck(options)) getRealValidate()(options);
109 };
110 },
111 get validateSchema() {
112 const validateSchema = require("./validateSchema");
113 return validateSchema;
114 },
115 get version() {
116 return /** @type {string} */ (require("../package.json").version);
117 },
118
119 get cli() {
120 return require("./cli");
121 },
122 get AutomaticPrefetchPlugin() {
123 return require("./AutomaticPrefetchPlugin");
124 },
125 get AsyncDependenciesBlock() {
126 return require("./AsyncDependenciesBlock");
127 },
128 get BannerPlugin() {
129 return require("./BannerPlugin");
130 },
131 get Cache() {
132 return require("./Cache");
133 },
134 get Chunk() {
135 return require("./Chunk");
136 },
137 get ChunkGraph() {
138 return require("./ChunkGraph");
139 },
140 get CleanPlugin() {
141 return require("./CleanPlugin");
142 },
143 get Compilation() {
144 return require("./Compilation");
145 },
146 get Compiler() {
147 return require("./Compiler");
148 },
149 get ConcatenationScope() {
150 return require("./ConcatenationScope");
151 },
152 get ContextExclusionPlugin() {
153 return require("./ContextExclusionPlugin");
154 },
155 get ContextReplacementPlugin() {
156 return require("./ContextReplacementPlugin");
157 },
158 get DefinePlugin() {
159 return require("./DefinePlugin");
160 },
161 get DelegatedPlugin() {
162 return require("./DelegatedPlugin");
163 },
164 get Dependency() {
165 return require("./Dependency");
166 },
167 get DllPlugin() {
168 return require("./DllPlugin");
169 },
170 get DllReferencePlugin() {
171 return require("./DllReferencePlugin");
172 },
173 get DynamicEntryPlugin() {
174 return require("./DynamicEntryPlugin");
175 },
176 get EntryOptionPlugin() {
177 return require("./EntryOptionPlugin");
178 },
179 get EntryPlugin() {
180 return require("./EntryPlugin");
181 },
182 get EnvironmentPlugin() {
183 return require("./EnvironmentPlugin");
184 },
185 get EvalDevToolModulePlugin() {
186 return require("./EvalDevToolModulePlugin");
187 },
188 get EvalSourceMapDevToolPlugin() {
189 return require("./EvalSourceMapDevToolPlugin");
190 },
191 get ExternalModule() {
192 return require("./ExternalModule");
193 },
194 get ExternalsPlugin() {
195 return require("./ExternalsPlugin");
196 },
197 get Generator() {
198 return require("./Generator");
199 },
200 get HotUpdateChunk() {
201 return require("./HotUpdateChunk");
202 },
203 get HotModuleReplacementPlugin() {
204 return require("./HotModuleReplacementPlugin");
205 },
206 get IgnorePlugin() {
207 return require("./IgnorePlugin");
208 },
209 get JavascriptModulesPlugin() {
210 return util.deprecate(
211 () => require("./javascript/JavascriptModulesPlugin"),
212 "webpack.JavascriptModulesPlugin has moved to webpack.javascript.JavascriptModulesPlugin",
213 "DEP_WEBPACK_JAVASCRIPT_MODULES_PLUGIN"
214 )();
215 },
216 get LibManifestPlugin() {
217 return require("./LibManifestPlugin");
218 },
219 get LibraryTemplatePlugin() {
220 return util.deprecate(
221 () => require("./LibraryTemplatePlugin"),
222 "webpack.LibraryTemplatePlugin is deprecated and has been replaced by compilation.outputOptions.library or compilation.addEntry + passing a library option",
223 "DEP_WEBPACK_LIBRARY_TEMPLATE_PLUGIN"
224 )();
225 },
226 get LoaderOptionsPlugin() {
227 return require("./LoaderOptionsPlugin");
228 },
229 get LoaderTargetPlugin() {
230 return require("./LoaderTargetPlugin");
231 },
232 get Module() {
233 return require("./Module");
234 },
235 get ModuleFilenameHelpers() {
236 return require("./ModuleFilenameHelpers");
237 },
238 get ModuleGraph() {
239 return require("./ModuleGraph");
240 },
241 get ModuleGraphConnection() {
242 return require("./ModuleGraphConnection");
243 },
244 get NoEmitOnErrorsPlugin() {
245 return require("./NoEmitOnErrorsPlugin");
246 },
247 get NormalModule() {
248 return require("./NormalModule");
249 },
250 get NormalModuleReplacementPlugin() {
251 return require("./NormalModuleReplacementPlugin");
252 },
253 get MultiCompiler() {
254 return require("./MultiCompiler");
255 },
256 get Parser() {
257 return require("./Parser");
258 },
259 get PrefetchPlugin() {
260 return require("./PrefetchPlugin");
261 },
262 get ProgressPlugin() {
263 return require("./ProgressPlugin");
264 },
265 get ProvidePlugin() {
266 return require("./ProvidePlugin");
267 },
268 get RuntimeGlobals() {
269 return require("./RuntimeGlobals");
270 },
271 get RuntimeModule() {
272 return require("./RuntimeModule");
273 },
274 get SingleEntryPlugin() {
275 return util.deprecate(
276 () => require("./EntryPlugin"),
277 "SingleEntryPlugin was renamed to EntryPlugin",
278 "DEP_WEBPACK_SINGLE_ENTRY_PLUGIN"
279 )();
280 },
281 get SourceMapDevToolPlugin() {
282 return require("./SourceMapDevToolPlugin");
283 },
284 get Stats() {
285 return require("./Stats");
286 },
287 get Template() {
288 return require("./Template");
289 },
290 get UsageState() {
291 return require("./ExportsInfo").UsageState;
292 },
293 get WatchIgnorePlugin() {
294 return require("./WatchIgnorePlugin");
295 },
296 get WebpackError() {
297 return require("./WebpackError");
298 },
299 get WebpackOptionsApply() {
300 return require("./WebpackOptionsApply");
301 },
302 get WebpackOptionsDefaulter() {
303 return util.deprecate(
304 () => require("./WebpackOptionsDefaulter"),
305 "webpack.WebpackOptionsDefaulter is deprecated and has been replaced by webpack.config.getNormalizedWebpackOptions and webpack.config.applyWebpackOptionsDefaults",
306 "DEP_WEBPACK_OPTIONS_DEFAULTER"
307 )();
308 },
309 // TODO webpack 6 deprecate
310 get WebpackOptionsValidationError() {
311 return require("schema-utils").ValidationError;
312 },
313 get ValidationError() {
314 return require("schema-utils").ValidationError;
315 },
316
317 cache: {
318 get MemoryCachePlugin() {
319 return require("./cache/MemoryCachePlugin");
320 }
321 },
322
323 config: {
324 get getNormalizedWebpackOptions() {
325 return require("./config/normalization").getNormalizedWebpackOptions;
326 },
327 get applyWebpackOptionsDefaults() {
328 return require("./config/defaults").applyWebpackOptionsDefaults;
329 }
330 },
331
332 dependencies: {
333 get ModuleDependency() {
334 return require("./dependencies/ModuleDependency");
335 },
336 get ConstDependency() {
337 return require("./dependencies/ConstDependency");
338 },
339 get NullDependency() {
340 return require("./dependencies/NullDependency");
341 }
342 },
343
344 ids: {
345 get ChunkModuleIdRangePlugin() {
346 return require("./ids/ChunkModuleIdRangePlugin");
347 },
348 get NaturalModuleIdsPlugin() {
349 return require("./ids/NaturalModuleIdsPlugin");
350 },
351 get OccurrenceModuleIdsPlugin() {
352 return require("./ids/OccurrenceModuleIdsPlugin");
353 },
354 get NamedModuleIdsPlugin() {
355 return require("./ids/NamedModuleIdsPlugin");
356 },
357 get DeterministicChunkIdsPlugin() {
358 return require("./ids/DeterministicChunkIdsPlugin");
359 },
360 get DeterministicModuleIdsPlugin() {
361 return require("./ids/DeterministicModuleIdsPlugin");
362 },
363 get NamedChunkIdsPlugin() {
364 return require("./ids/NamedChunkIdsPlugin");
365 },
366 get OccurrenceChunkIdsPlugin() {
367 return require("./ids/OccurrenceChunkIdsPlugin");
368 },
369 get HashedModuleIdsPlugin() {
370 return require("./ids/HashedModuleIdsPlugin");
371 }
372 },
373
374 javascript: {
375 get EnableChunkLoadingPlugin() {
376 return require("./javascript/EnableChunkLoadingPlugin");
377 },
378 get JavascriptModulesPlugin() {
379 return require("./javascript/JavascriptModulesPlugin");
380 },
381 get JavascriptParser() {
382 return require("./javascript/JavascriptParser");
383 }
384 },
385
386 optimize: {
387 get AggressiveMergingPlugin() {
388 return require("./optimize/AggressiveMergingPlugin");
389 },
390 get AggressiveSplittingPlugin() {
391 return util.deprecate(
392 () => require("./optimize/AggressiveSplittingPlugin"),
393 "AggressiveSplittingPlugin is deprecated in favor of SplitChunksPlugin",
394 "DEP_WEBPACK_AGGRESSIVE_SPLITTING_PLUGIN"
395 )();
396 },
397 get InnerGraph() {
398 return require("./optimize/InnerGraph");
399 },
400 get LimitChunkCountPlugin() {
401 return require("./optimize/LimitChunkCountPlugin");
402 },
403 get MinChunkSizePlugin() {
404 return require("./optimize/MinChunkSizePlugin");
405 },
406 get ModuleConcatenationPlugin() {
407 return require("./optimize/ModuleConcatenationPlugin");
408 },
409 get RealContentHashPlugin() {
410 return require("./optimize/RealContentHashPlugin");
411 },
412 get RuntimeChunkPlugin() {
413 return require("./optimize/RuntimeChunkPlugin");
414 },
415 get SideEffectsFlagPlugin() {
416 return require("./optimize/SideEffectsFlagPlugin");
417 },
418 get SplitChunksPlugin() {
419 return require("./optimize/SplitChunksPlugin");
420 }
421 },
422
423 runtime: {
424 get GetChunkFilenameRuntimeModule() {
425 return require("./runtime/GetChunkFilenameRuntimeModule");
426 },
427 get LoadScriptRuntimeModule() {
428 return require("./runtime/LoadScriptRuntimeModule");
429 }
430 },
431
432 prefetch: {
433 get ChunkPrefetchPreloadPlugin() {
434 return require("./prefetch/ChunkPrefetchPreloadPlugin");
435 }
436 },
437
438 web: {
439 get FetchCompileAsyncWasmPlugin() {
440 return require("./web/FetchCompileAsyncWasmPlugin");
441 },
442 get FetchCompileWasmPlugin() {
443 return require("./web/FetchCompileWasmPlugin");
444 },
445 get JsonpChunkLoadingRuntimeModule() {
446 return require("./web/JsonpChunkLoadingRuntimeModule");
447 },
448 get JsonpTemplatePlugin() {
449 return require("./web/JsonpTemplatePlugin");
450 }
451 },
452
453 webworker: {
454 get WebWorkerTemplatePlugin() {
455 return require("./webworker/WebWorkerTemplatePlugin");
456 }
457 },
458
459 node: {
460 get NodeEnvironmentPlugin() {
461 return require("./node/NodeEnvironmentPlugin");
462 },
463 get NodeSourcePlugin() {
464 return require("./node/NodeSourcePlugin");
465 },
466 get NodeTargetPlugin() {
467 return require("./node/NodeTargetPlugin");
468 },
469 get NodeTemplatePlugin() {
470 return require("./node/NodeTemplatePlugin");
471 },
472 get ReadFileCompileWasmPlugin() {
473 return require("./node/ReadFileCompileWasmPlugin");
474 }
475 },
476
477 electron: {
478 get ElectronTargetPlugin() {
479 return require("./electron/ElectronTargetPlugin");
480 }
481 },
482
483 wasm: {
484 get AsyncWebAssemblyModulesPlugin() {
485 return require("./wasm-async/AsyncWebAssemblyModulesPlugin");
486 }
487 },
488
489 library: {
490 get AbstractLibraryPlugin() {
491 return require("./library/AbstractLibraryPlugin");
492 },
493 get EnableLibraryPlugin() {
494 return require("./library/EnableLibraryPlugin");
495 }
496 },
497
498 container: {
499 get ContainerPlugin() {
500 return require("./container/ContainerPlugin");
501 },
502 get ContainerReferencePlugin() {
503 return require("./container/ContainerReferencePlugin");
504 },
505 get ModuleFederationPlugin() {
506 return require("./container/ModuleFederationPlugin");
507 },
508 get scope() {
509 return require("./container/options").scope;
510 }
511 },
512
513 sharing: {
514 get ConsumeSharedPlugin() {
515 return require("./sharing/ConsumeSharedPlugin");
516 },
517 get ProvideSharedPlugin() {
518 return require("./sharing/ProvideSharedPlugin");
519 },
520 get SharePlugin() {
521 return require("./sharing/SharePlugin");
522 },
523 get scope() {
524 return require("./container/options").scope;
525 }
526 },
527
528 debug: {
529 get ProfilingPlugin() {
530 return require("./debug/ProfilingPlugin");
531 }
532 },
533
534 util: {
535 get createHash() {
536 return require("./util/createHash");
537 },
538 get comparators() {
539 return require("./util/comparators");
540 },
541 get runtime() {
542 return require("./util/runtime");
543 },
544 get serialization() {
545 return require("./util/serialization");
546 },
547 get cleverMerge() {
548 return require("./util/cleverMerge").cachedCleverMerge;
549 },
550 get LazySet() {
551 return require("./util/LazySet");
552 }
553 },
554
555 get sources() {
556 return require("webpack-sources");
557 },
558
559 experiments: {
560 schemes: {
561 get HttpUriPlugin() {
562 return require("./schemes/HttpUriPlugin");
563 }
564 }
565 }
566});