2018-12-09 21:26:35 +08:00
/ *
MIT License http : //www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @ sokra
* /
"use strict" ;
const util = require ( "util" ) ;
2020-02-17 17:27:46 +08:00
const memorize = require ( "./util/memorize" ) ;
2018-12-09 21:26:35 +08:00
2020-04-23 03:21:30 +08:00
/** @typedef {import("../declarations/WebpackOptions").Entry} Entry */
/** @typedef {import("../declarations/WebpackOptions").EntryNormalized} EntryNormalized */
/** @typedef {import("../declarations/WebpackOptions").LibraryOptions} LibraryOptions */
/** @typedef {import("../declarations/WebpackOptions").ModuleOptions} ModuleOptions */
/** @typedef {import("../declarations/WebpackOptions").ResolveOptions} ResolveOptions */
2020-10-08 16:35:58 +08:00
/** @typedef {import("../declarations/WebpackOptions").RuleSetCondition} RuleSetCondition */
2020-10-08 16:37:46 +08:00
/** @typedef {import("../declarations/WebpackOptions").RuleSetConditionAbsolute} RuleSetConditionAbsolute */
2020-04-23 03:21:30 +08:00
/** @typedef {import("../declarations/WebpackOptions").RuleSetRule} RuleSetRule */
2020-10-08 16:39:05 +08:00
/** @typedef {import("../declarations/WebpackOptions").RuleSetUse} RuleSetUse */
2020-03-21 21:01:38 +08:00
/** @typedef {import("../declarations/WebpackOptions").WebpackOptions} Configuration */
2020-04-23 03:21:30 +08:00
/** @typedef {import("../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptionsNormalized */
2020-04-20 13:36:55 +08:00
/** @typedef {import("../declarations/WebpackOptions").WebpackPluginFunction} WebpackPluginFunction */
/** @typedef {import("../declarations/WebpackOptions").WebpackPluginInstance} WebpackPluginInstance */
/** @typedef {import("./Parser").ParserState} ParserState */
2020-03-21 21:01:38 +08:00
2020-04-20 13:36:55 +08:00
/ * *
* @ template { Function } T
* @ param { function ( ) : T } factory factory function
* @ returns { T } function
* /
const lazyFunction = factory => {
const fac = memorize ( factory ) ;
const f = /** @type {any} */ ( ( ... args ) => {
return fac ( ) ( ... args ) ;
} ) ;
return /** @type {T} */ ( f ) ;
} ;
/ * *
* @ template A
* @ template B
* @ param { A } obj input a
* @ param { B } exports input b
* @ returns { A & B } merged
* /
const mergeExports = ( obj , exports ) => {
const descriptors = Object . getOwnPropertyDescriptors ( exports ) ;
for ( const name of Object . keys ( descriptors ) ) {
const descriptor = descriptors [ name ] ;
if ( descriptor . get ) {
const fn = descriptor . get ;
Object . defineProperty ( obj , name , {
configurable : false ,
enumerable : true ,
get : memorize ( fn )
} ) ;
} else if ( typeof descriptor . value === "object" ) {
Object . defineProperty ( obj , name , {
configurable : false ,
enumerable : true ,
writable : false ,
value : mergeExports ( { } , descriptor . value )
} ) ;
} else {
throw new Error (
"Exposed values must be either a getter or an nested object"
) ;
}
}
return /** @type {A & B} */ ( Object . freeze ( obj ) ) ;
} ;
const fn = lazyFunction ( ( ) => require ( "./webpack" ) ) ;
module . exports = mergeExports ( fn , {
get webpack ( ) {
return require ( "./webpack" ) ;
} ,
get validate ( ) {
const validateSchema = require ( "./validateSchema" ) ;
const webpackOptionsSchema = require ( "../schemas/WebpackOptions.json" ) ;
2020-04-21 14:54:59 +08:00
return options => validateSchema ( webpackOptionsSchema , options ) ;
2020-04-20 13:36:55 +08:00
} ,
get validateSchema ( ) {
const validateSchema = require ( "./validateSchema" ) ;
return validateSchema ;
} ,
get version ( ) {
2020-04-21 14:54:59 +08:00
return /** @type {string} */ ( require ( "../package.json" ) . version ) ;
2020-04-20 13:36:55 +08:00
} ,
2018-12-09 21:26:35 +08:00
2020-03-21 21:01:38 +08:00
get cli ( ) {
return require ( "./cli" ) ;
} ,
get AutomaticPrefetchPlugin ( ) {
return require ( "./AutomaticPrefetchPlugin" ) ;
} ,
get BannerPlugin ( ) {
return require ( "./BannerPlugin" ) ;
} ,
get Cache ( ) {
return require ( "./Cache" ) ;
} ,
2020-04-20 13:36:55 +08:00
get Chunk ( ) {
return require ( "./Chunk" ) ;
} ,
get ChunkGraph ( ) {
return require ( "./ChunkGraph" ) ;
} ,
2020-03-21 21:01:38 +08:00
get Compilation ( ) {
return require ( "./Compilation" ) ;
} ,
get Compiler ( ) {
return require ( "./Compiler" ) ;
} ,
2020-09-15 16:56:06 +08:00
get ConcatenationScope ( ) {
return require ( "./ConcatenationScope" ) ;
} ,
2020-03-21 21:01:38 +08:00
get ContextExclusionPlugin ( ) {
return require ( "./ContextExclusionPlugin" ) ;
} ,
get ContextReplacementPlugin ( ) {
return require ( "./ContextReplacementPlugin" ) ;
} ,
get DefinePlugin ( ) {
return require ( "./DefinePlugin" ) ;
} ,
get DelegatedPlugin ( ) {
return require ( "./DelegatedPlugin" ) ;
} ,
get Dependency ( ) {
return require ( "./Dependency" ) ;
} ,
get DllPlugin ( ) {
return require ( "./DllPlugin" ) ;
} ,
get DllReferencePlugin ( ) {
return require ( "./DllReferencePlugin" ) ;
} ,
get EntryPlugin ( ) {
return require ( "./EntryPlugin" ) ;
} ,
get EnvironmentPlugin ( ) {
return require ( "./EnvironmentPlugin" ) ;
} ,
get EvalDevToolModulePlugin ( ) {
return require ( "./EvalDevToolModulePlugin" ) ;
} ,
get EvalSourceMapDevToolPlugin ( ) {
return require ( "./EvalSourceMapDevToolPlugin" ) ;
} ,
2020-04-20 13:36:55 +08:00
get ExternalModule ( ) {
return require ( "./ExternalModule" ) ;
} ,
2020-03-21 21:01:38 +08:00
get ExternalsPlugin ( ) {
return require ( "./ExternalsPlugin" ) ;
} ,
get Generator ( ) {
return require ( "./Generator" ) ;
} ,
2020-09-25 02:29:08 +08:00
get HotUpdateChunk ( ) {
return require ( "./HotUpdateChunk" ) ;
} ,
2020-03-21 21:01:38 +08:00
get HotModuleReplacementPlugin ( ) {
return require ( "./HotModuleReplacementPlugin" ) ;
} ,
get IgnorePlugin ( ) {
return require ( "./IgnorePlugin" ) ;
} ,
get JavascriptModulesPlugin ( ) {
return util . deprecate (
( ) => require ( "./javascript/JavascriptModulesPlugin" ) ,
"webpack.JavascriptModulesPlugin has moved to webpack.javascript.JavascriptModulesPlugin" ,
"DEP_WEBPACK_JAVASCRIPT_MODULES_PLUGIN"
) ( ) ;
} ,
get LibManifestPlugin ( ) {
return require ( "./LibManifestPlugin" ) ;
} ,
get LibraryTemplatePlugin ( ) {
return util . deprecate (
( ) => require ( "./LibraryTemplatePlugin" ) ,
"webpack.LibraryTemplatePlugin is deprecated and has been replaced by compilation.outputOptions.library or compilation.addEntry + passing a library option" ,
"DEP_WEBPACK_LIBRARY_TEMPLATE_PLUGIN"
) ( ) ;
} ,
get LoaderOptionsPlugin ( ) {
return require ( "./LoaderOptionsPlugin" ) ;
} ,
get LoaderTargetPlugin ( ) {
return require ( "./LoaderTargetPlugin" ) ;
} ,
get Module ( ) {
return require ( "./Module" ) ;
} ,
get ModuleFilenameHelpers ( ) {
return require ( "./ModuleFilenameHelpers" ) ;
} ,
2020-04-20 13:36:55 +08:00
get ModuleGraph ( ) {
return require ( "./ModuleGraph" ) ;
} ,
2020-10-05 22:57:31 +08:00
get ModuleGraphConnection ( ) {
return require ( "./ModuleGraphConnection" ) ;
} ,
2020-03-21 21:01:38 +08:00
get NoEmitOnErrorsPlugin ( ) {
return require ( "./NoEmitOnErrorsPlugin" ) ;
} ,
get NormalModule ( ) {
return require ( "./NormalModule" ) ;
} ,
get NormalModuleReplacementPlugin ( ) {
return require ( "./NormalModuleReplacementPlugin" ) ;
} ,
get MultiCompiler ( ) {
return require ( "./MultiCompiler" ) ;
} ,
get Parser ( ) {
return require ( "./Parser" ) ;
} ,
get PrefetchPlugin ( ) {
return require ( "./PrefetchPlugin" ) ;
} ,
get ProgressPlugin ( ) {
return require ( "./ProgressPlugin" ) ;
} ,
get ProvidePlugin ( ) {
return require ( "./ProvidePlugin" ) ;
} ,
get RuntimeGlobals ( ) {
return require ( "./RuntimeGlobals" ) ;
} ,
get RuntimeModule ( ) {
return require ( "./RuntimeModule" ) ;
} ,
get SingleEntryPlugin ( ) {
return util . deprecate (
( ) => require ( "./EntryPlugin" ) ,
"SingleEntryPlugin was renamed to EntryPlugin" ,
"DEP_WEBPACK_SINGLE_ENTRY_PLUGIN"
) ( ) ;
} ,
get SourceMapDevToolPlugin ( ) {
return require ( "./SourceMapDevToolPlugin" ) ;
} ,
get Stats ( ) {
return require ( "./Stats" ) ;
} ,
get Template ( ) {
return require ( "./Template" ) ;
} ,
2020-07-28 01:36:06 +08:00
get UsageState ( ) {
return require ( "./ExportsInfo" ) . UsageState ;
} ,
2020-03-21 21:01:38 +08:00
get WatchIgnorePlugin ( ) {
return require ( "./WatchIgnorePlugin" ) ;
} ,
2020-04-20 13:36:55 +08:00
get WebpackOptionsApply ( ) {
return require ( "./WebpackOptionsApply" ) ;
} ,
2020-03-21 21:01:38 +08:00
get WebpackOptionsDefaulter ( ) {
return util . deprecate (
( ) => require ( "./WebpackOptionsDefaulter" ) ,
"webpack.WebpackOptionsDefaulter is deprecated and has been replaced by webpack.config.getNormalizedWebpackOptions and webpack.config.applyWebpackOptionsDefaults" ,
"DEP_WEBPACK_OPTIONS_DEFAULTER"
) ( ) ;
} ,
2020-02-17 17:27:46 +08:00
// TODO webpack 6 deprecate
2020-03-21 21:01:38 +08:00
get WebpackOptionsValidationError ( ) {
2020-04-20 13:36:55 +08:00
return require ( "schema-utils" ) . ValidationError ;
2020-03-21 21:01:38 +08:00
} ,
get ValidationError ( ) {
2020-04-20 13:36:55 +08:00
return require ( "schema-utils" ) . ValidationError ;
2020-03-21 21:01:38 +08:00
} ,
2018-12-09 21:26:35 +08:00
2020-03-21 21:01:38 +08:00
cache : {
get MemoryCachePlugin ( ) {
return require ( "./cache/MemoryCachePlugin" ) ;
}
} ,
2018-12-09 21:26:35 +08:00
2020-03-21 21:01:38 +08:00
config : {
get getNormalizedWebpackOptions ( ) {
return require ( "./config/normalization" ) . getNormalizedWebpackOptions ;
} ,
get applyWebpackOptionsDefaults ( ) {
return require ( "./config/defaults" ) . applyWebpackOptionsDefaults ;
}
} ,
2020-02-17 17:27:46 +08:00
2020-03-21 21:01:38 +08:00
ids : {
get ChunkModuleIdRangePlugin ( ) {
return require ( "./ids/ChunkModuleIdRangePlugin" ) ;
} ,
get NaturalModuleIdsPlugin ( ) {
return require ( "./ids/NaturalModuleIdsPlugin" ) ;
} ,
get OccurrenceModuleIdsPlugin ( ) {
return require ( "./ids/OccurrenceModuleIdsPlugin" ) ;
} ,
get NamedModuleIdsPlugin ( ) {
return require ( "./ids/NamedModuleIdsPlugin" ) ;
} ,
2020-03-26 20:50:16 +08:00
get DeterministicChunkIdsPlugin ( ) {
return require ( "./ids/DeterministicChunkIdsPlugin" ) ;
} ,
2020-03-21 21:01:38 +08:00
get DeterministicModuleIdsPlugin ( ) {
return require ( "./ids/DeterministicModuleIdsPlugin" ) ;
} ,
get NamedChunkIdsPlugin ( ) {
return require ( "./ids/NamedChunkIdsPlugin" ) ;
} ,
get OccurrenceChunkIdsPlugin ( ) {
return require ( "./ids/OccurrenceChunkIdsPlugin" ) ;
} ,
get HashedModuleIdsPlugin ( ) {
return require ( "./ids/HashedModuleIdsPlugin" ) ;
}
} ,
2018-12-09 21:26:35 +08:00
2020-03-21 21:01:38 +08:00
javascript : {
2020-08-26 03:45:56 +08:00
get EnableChunkLoadingPlugin ( ) {
return require ( "./javascript/EnableChunkLoadingPlugin" ) ;
} ,
2020-03-21 21:01:38 +08:00
get JavascriptModulesPlugin ( ) {
return require ( "./javascript/JavascriptModulesPlugin" ) ;
2020-08-28 07:25:34 +08:00
} ,
get JavascriptParser ( ) {
return require ( "./javascript/JavascriptParser" ) ;
2020-03-21 21:01:38 +08:00
}
} ,
2019-10-22 15:09:28 +08:00
2020-03-21 21:01:38 +08:00
optimize : {
get AggressiveMergingPlugin ( ) {
return require ( "./optimize/AggressiveMergingPlugin" ) ;
} ,
get AggressiveSplittingPlugin ( ) {
return util . deprecate (
( ) => require ( "./optimize/AggressiveSplittingPlugin" ) ,
"AggressiveSplittingPlugin is deprecated in favor of SplitChunksPlugin" ,
"DEP_WEBPACK_AGGRESSIVE_SPLITTING_PLUGIN"
) ( ) ;
} ,
get LimitChunkCountPlugin ( ) {
return require ( "./optimize/LimitChunkCountPlugin" ) ;
} ,
get MinChunkSizePlugin ( ) {
return require ( "./optimize/MinChunkSizePlugin" ) ;
} ,
get ModuleConcatenationPlugin ( ) {
return require ( "./optimize/ModuleConcatenationPlugin" ) ;
} ,
get RuntimeChunkPlugin ( ) {
return require ( "./optimize/RuntimeChunkPlugin" ) ;
} ,
get SideEffectsFlagPlugin ( ) {
return require ( "./optimize/SideEffectsFlagPlugin" ) ;
} ,
get SplitChunksPlugin ( ) {
return require ( "./optimize/SplitChunksPlugin" ) ;
}
} ,
2018-12-09 21:26:35 +08:00
2020-08-19 21:05:49 +08:00
runtime : {
2020-09-25 02:29:08 +08:00
get GetChunkFilenameRuntimeModule ( ) {
return require ( "./runtime/GetChunkFilenameRuntimeModule" ) ;
} ,
2020-08-19 21:05:49 +08:00
get LoadScriptRuntimeModule ( ) {
return require ( "./runtime/LoadScriptRuntimeModule" ) ;
}
} ,
2020-08-20 05:17:33 +08:00
prefetch : {
get ChunkPrefetchPreloadPlugin ( ) {
return require ( "./prefetch/ChunkPrefetchPreloadPlugin" ) ;
}
} ,
2020-03-21 21:01:38 +08:00
web : {
2020-08-20 05:17:33 +08:00
get FetchCompileAsyncWasmPlugin ( ) {
return require ( "./web/FetchCompileAsyncWasmPlugin" ) ;
} ,
2020-03-21 21:01:38 +08:00
get FetchCompileWasmPlugin ( ) {
return require ( "./web/FetchCompileWasmPlugin" ) ;
} ,
2020-08-25 19:20:29 +08:00
get JsonpChunkLoadingRuntimeModule ( ) {
return require ( "./web/JsonpChunkLoadingRuntimeModule" ) ;
} ,
2020-03-21 21:01:38 +08:00
get JsonpTemplatePlugin ( ) {
return require ( "./web/JsonpTemplatePlugin" ) ;
}
} ,
2018-12-09 21:26:35 +08:00
2020-03-21 21:01:38 +08:00
webworker : {
get WebWorkerTemplatePlugin ( ) {
return require ( "./webworker/WebWorkerTemplatePlugin" ) ;
}
} ,
2018-12-09 21:26:35 +08:00
2020-03-21 21:01:38 +08:00
node : {
get NodeEnvironmentPlugin ( ) {
return require ( "./node/NodeEnvironmentPlugin" ) ;
} ,
2020-08-20 05:17:33 +08:00
get NodeSourcePlugin ( ) {
return require ( "./node/NodeSourcePlugin" ) ;
} ,
get NodeTargetPlugin ( ) {
return require ( "./node/NodeTargetPlugin" ) ;
} ,
2020-03-21 21:01:38 +08:00
get NodeTemplatePlugin ( ) {
return require ( "./node/NodeTemplatePlugin" ) ;
} ,
get ReadFileCompileWasmPlugin ( ) {
return require ( "./node/ReadFileCompileWasmPlugin" ) ;
}
} ,
2018-12-09 21:26:35 +08:00
2020-08-20 05:17:33 +08:00
electron : {
get ElectronTargetPlugin ( ) {
return require ( "./electron/ElectronTargetPlugin" ) ;
}
} ,
2020-03-21 21:01:38 +08:00
wasm : {
get AsyncWebAssemblyModulesPlugin ( ) {
return require ( "./wasm-async/AsyncWebAssemblyModulesPlugin" ) ;
}
} ,
2019-10-09 19:50:52 +08:00
2020-03-21 21:01:38 +08:00
library : {
get AbstractLibraryPlugin ( ) {
return require ( "./library/AbstractLibraryPlugin" ) ;
} ,
get EnableLibraryPlugin ( ) {
return require ( "./library/EnableLibraryPlugin" ) ;
}
} ,
2020-02-20 03:25:49 +08:00
2020-04-22 18:09:11 +08:00
container : {
get ContainerPlugin ( ) {
return require ( "./container/ContainerPlugin" ) ;
} ,
get ContainerReferencePlugin ( ) {
return require ( "./container/ContainerReferencePlugin" ) ;
} ,
get ModuleFederationPlugin ( ) {
return require ( "./container/ModuleFederationPlugin" ) ;
} ,
2020-05-14 21:50:35 +08:00
get scope ( ) {
return require ( "./container/options" ) . scope ;
2020-04-22 18:09:11 +08:00
}
} ,
2020-05-23 22:08:51 +08:00
sharing : {
2020-05-26 05:14:19 +08:00
get ConsumeSharedPlugin ( ) {
return require ( "./sharing/ConsumeSharedPlugin" ) ;
} ,
2020-05-23 22:08:51 +08:00
get ProvideSharedPlugin ( ) {
return require ( "./sharing/ProvideSharedPlugin" ) ;
} ,
2020-05-26 06:46:09 +08:00
get SharePlugin ( ) {
return require ( "./sharing/SharePlugin" ) ;
} ,
2020-05-23 22:08:51 +08:00
get scope ( ) {
return require ( "./container/options" ) . scope ;
}
} ,
2020-03-21 21:01:38 +08:00
debug : {
get ProfilingPlugin ( ) {
return require ( "./debug/ProfilingPlugin" ) ;
}
} ,
2018-12-09 21:26:35 +08:00
2020-03-21 21:01:38 +08:00
util : {
get createHash ( ) {
return require ( "./util/createHash" ) ;
} ,
get comparators ( ) {
return require ( "./util/comparators" ) ;
} ,
get serialization ( ) {
return require ( "./util/serialization" ) ;
}
2020-07-03 20:45:49 +08:00
} ,
2020-08-20 02:05:47 +08:00
get sources ( ) {
return require ( "webpack-sources" ) ;
} ,
2020-07-03 20:45:49 +08:00
experiments : {
schemes : {
get HttpUriPlugin ( ) {
return require ( "./schemes/HttpUriPlugin" ) ;
2020-07-06 23:45:09 +08:00
} ,
get HttpsUriPlugin ( ) {
return require ( "./schemes/HttpsUriPlugin" ) ;
2020-07-03 20:45:49 +08:00
}
}
2020-03-21 21:01:38 +08:00
}
2018-12-09 21:26:35 +08:00
} ) ;