webpack 5.99.8 → 5.100.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -3
- package/bin/webpack.js +8 -2
- package/hot/log.js +15 -15
- package/hot/poll.js +1 -0
- package/lib/APIPlugin.js +3 -3
- package/lib/AbstractMethodError.js +1 -0
- package/lib/AutomaticPrefetchPlugin.js +1 -0
- package/lib/BannerPlugin.js +1 -1
- package/lib/CacheFacade.js +2 -1
- package/lib/CaseSensitiveModulesWarning.js +4 -4
- package/lib/Chunk.js +6 -6
- package/lib/ChunkGraph.js +37 -32
- package/lib/ChunkGroup.js +17 -10
- package/lib/ChunkTemplate.js +1 -1
- package/lib/CleanPlugin.js +94 -17
- package/lib/CodeGenerationResults.js +1 -1
- package/lib/CompatibilityPlugin.js +5 -2
- package/lib/Compilation.js +77 -71
- package/lib/Compiler.js +46 -16
- package/lib/ConcatenationScope.js +15 -6
- package/lib/ConstPlugin.js +65 -45
- package/lib/ContextModule.js +16 -12
- package/lib/ContextModuleFactory.js +4 -3
- package/lib/ContextReplacementPlugin.js +4 -2
- package/lib/CssModule.js +2 -3
- package/lib/DefinePlugin.js +111 -3
- package/lib/DelegatedModuleFactoryPlugin.js +18 -18
- package/lib/Dependency.js +16 -12
- package/lib/DependencyTemplate.js +1 -0
- package/lib/DllEntryPlugin.js +3 -1
- package/lib/DllPlugin.js +4 -3
- package/lib/DllReferencePlugin.js +2 -2
- package/lib/DynamicEntryPlugin.js +1 -1
- package/lib/EntryOptionPlugin.js +5 -0
- package/lib/ErrorHelpers.js +4 -4
- package/lib/EvalDevToolModulePlugin.js +3 -3
- package/lib/EvalSourceMapDevToolPlugin.js +7 -7
- package/lib/ExportsInfo.js +48 -39
- package/lib/ExternalModule.js +15 -11
- package/lib/ExternalModuleFactoryPlugin.js +5 -2
- package/lib/FileSystemInfo.js +51 -38
- package/lib/FlagDependencyExportsPlugin.js +14 -7
- package/lib/FlagDependencyUsagePlugin.js +1 -1
- package/lib/Generator.js +14 -1
- package/lib/HookWebpackError.js +1 -0
- package/lib/HotModuleReplacementPlugin.js +77 -50
- package/lib/IgnorePlugin.js +1 -1
- package/lib/InvalidDependenciesModuleWarning.js +1 -1
- package/lib/JavascriptMetaInfoPlugin.js +0 -1
- package/lib/LibManifestPlugin.js +4 -2
- package/lib/LoaderOptionsPlugin.js +6 -4
- package/lib/MainTemplate.js +2 -2
- package/lib/Module.js +21 -6
- package/lib/ModuleFactory.js +1 -0
- package/lib/ModuleGraph.js +24 -2
- package/lib/ModuleGraphConnection.js +5 -5
- package/lib/ModuleInfoHeaderPlugin.js +2 -1
- package/lib/ModuleParseError.js +1 -0
- package/lib/ModuleSourceTypesConstants.js +12 -12
- package/lib/ModuleTemplate.js +1 -1
- package/lib/ModuleTypeConstants.js +21 -21
- package/lib/MultiCompiler.js +6 -6
- package/lib/NormalModule.js +61 -56
- package/lib/NormalModuleFactory.js +52 -37
- package/lib/NormalModuleReplacementPlugin.js +1 -1
- package/lib/NullFactory.js +1 -0
- package/lib/OptimizationStages.js +1 -1
- package/lib/Parser.js +1 -0
- package/lib/ProgressPlugin.js +12 -5
- package/lib/ProvidePlugin.js +5 -1
- package/lib/RecordIdsPlugin.js +3 -3
- package/lib/RuntimeGlobals.js +175 -155
- package/lib/RuntimeModule.js +1 -0
- package/lib/RuntimePlugin.js +34 -8
- package/lib/RuntimeTemplate.js +111 -11
- package/lib/SourceMapDevToolModuleOptionsPlugin.js +15 -25
- package/lib/SourceMapDevToolPlugin.js +19 -17
- package/lib/Template.js +2 -2
- package/lib/TemplatedPathPlugin.js +1 -1
- package/lib/WarnDeprecatedOptionPlugin.js +7 -8
- package/lib/WatchIgnorePlugin.js +4 -3
- package/lib/WebpackIsIncludedPlugin.js +2 -1
- package/lib/WebpackOptionsApply.js +115 -27
- package/lib/asset/AssetGenerator.js +26 -21
- package/lib/asset/AssetModulesPlugin.js +19 -17
- package/lib/asset/AssetSourceGenerator.js +11 -9
- package/lib/asset/RawDataUrlModule.js +4 -2
- package/lib/async-modules/AwaitDependenciesInitFragment.js +1 -1
- package/lib/buildChunkGraph.js +6 -3
- package/lib/cache/AddBuildDependenciesPlugin.js +5 -6
- package/lib/cache/IdleFileCachePlugin.js +7 -4
- package/lib/cache/MemoryCachePlugin.js +1 -0
- package/lib/cache/MemoryWithGcCachePlugin.js +1 -0
- package/lib/cache/PackFileCacheStrategy.js +26 -20
- package/lib/cache/ResolverCachePlugin.js +16 -8
- package/lib/cli.js +15 -10
- package/lib/config/browserslistTargetHandler.js +3 -3
- package/lib/config/defaults.js +25 -17
- package/lib/config/normalization.js +2 -1
- package/lib/config/target.js +6 -5
- package/lib/container/ContainerPlugin.js +1 -1
- package/lib/container/ContainerReferencePlugin.js +1 -1
- package/lib/container/FallbackModule.js +2 -1
- package/lib/container/HoistContainerReferencesPlugin.js +1 -1
- package/lib/container/ModuleFederationPlugin.js +2 -2
- package/lib/container/RemoteModule.js +1 -1
- package/lib/css/CssGenerator.js +9 -6
- package/lib/css/CssModulesPlugin.js +44 -31
- package/lib/css/CssParser.js +6 -4
- package/lib/css/walkCssTokens.js +33 -37
- package/lib/debug/ProfilingPlugin.js +6 -6
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +8 -8
- package/lib/dependencies/AMDPlugin.js +12 -8
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +28 -26
- package/lib/dependencies/CachedConstDependency.js +1 -5
- package/lib/dependencies/CommonJsExportRequireDependency.js +6 -4
- package/lib/dependencies/CommonJsExportsParserPlugin.js +22 -25
- package/lib/dependencies/CommonJsFullRequireDependency.js +1 -9
- package/lib/dependencies/CommonJsImportsParserPlugin.js +100 -114
- package/lib/dependencies/CommonJsPlugin.js +15 -16
- package/lib/dependencies/ContextDependencyHelpers.js +2 -1
- package/lib/dependencies/ContextDependencyTemplateAsId.js +1 -0
- package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +1 -0
- package/lib/dependencies/CssIcssExportDependency.js +1 -1
- package/lib/dependencies/CssLocalIdentifierDependency.js +2 -2
- package/lib/dependencies/CssSelfLocalIdentifierDependency.js +2 -1
- package/lib/dependencies/CssUrlDependency.js +1 -1
- package/lib/dependencies/DynamicExports.js +9 -9
- package/lib/dependencies/ExportsInfoDependency.js +1 -1
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +122 -101
- package/lib/dependencies/HarmonyExportExpressionDependency.js +1 -1
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +95 -19
- package/lib/dependencies/HarmonyExportInitFragment.js +1 -1
- package/lib/dependencies/HarmonyImportDependency.js +11 -5
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +238 -162
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +4 -1
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +20 -9
- package/lib/dependencies/HarmonyModulesPlugin.js +23 -12
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -0
- package/lib/dependencies/ImportMetaContextPlugin.js +2 -1
- package/lib/dependencies/ImportMetaPlugin.js +2 -2
- package/lib/dependencies/ImportParserPlugin.js +40 -9
- package/lib/dependencies/ImportPlugin.js +3 -1
- package/lib/dependencies/LoaderPlugin.js +1 -0
- package/lib/dependencies/ModuleDependency.js +1 -1
- package/lib/dependencies/ModuleDependencyTemplateAsRequireId.js +1 -0
- package/lib/dependencies/RequireContextPlugin.js +3 -1
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +3 -0
- package/lib/dependencies/RequireEnsurePlugin.js +6 -6
- package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +33 -34
- package/lib/dependencies/RequireIncludePlugin.js +1 -0
- package/lib/dependencies/RuntimeRequirementsDependency.js +1 -1
- package/lib/dependencies/SystemPlugin.js +1 -1
- package/lib/dependencies/URLContextDependency.js +65 -0
- package/lib/dependencies/URLDependency.js +1 -1
- package/lib/dependencies/URLPlugin.js +17 -157
- package/lib/dependencies/WorkerPlugin.js +23 -10
- package/lib/dependencies/processExportInfo.js +2 -1
- package/lib/esm/ModuleChunkFormatPlugin.js +269 -185
- package/lib/esm/ModuleChunkLoadingPlugin.js +39 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +73 -6
- package/lib/hmr/HotModuleReplacement.runtime.js +0 -1
- package/lib/hmr/HotModuleReplacementRuntimeModule.js +1 -1
- package/lib/hmr/JavascriptHotModuleReplacementHelper.js +37 -0
- package/lib/hmr/LazyCompilationPlugin.js +4 -2
- package/lib/hmr/lazyCompilationBackend.js +4 -2
- package/lib/ids/ChunkModuleIdRangePlugin.js +6 -3
- package/lib/ids/DeterministicChunkIdsPlugin.js +30 -35
- package/lib/ids/DeterministicModuleIdsPlugin.js +4 -3
- package/lib/ids/HashedModuleIdsPlugin.js +5 -4
- package/lib/ids/IdHelpers.js +21 -17
- package/lib/ids/NamedChunkIdsPlugin.js +5 -5
- package/lib/ids/NamedModuleIdsPlugin.js +4 -4
- package/lib/ids/NaturalChunkIdsPlugin.js +2 -1
- package/lib/ids/NaturalModuleIdsPlugin.js +1 -1
- package/lib/ids/OccurrenceChunkIdsPlugin.js +3 -2
- package/lib/ids/OccurrenceModuleIdsPlugin.js +1 -1
- package/lib/ids/SyncModuleIdsPlugin.js +1 -1
- package/lib/index.js +13 -3
- package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +113 -119
- package/lib/javascript/BasicEvaluatedExpression.js +2 -1
- package/lib/javascript/ChunkHelpers.js +1 -0
- package/lib/javascript/CommonJsChunkFormatPlugin.js +121 -136
- package/lib/javascript/EnableChunkLoadingPlugin.js +6 -3
- package/lib/javascript/JavascriptGenerator.js +14 -2
- package/lib/javascript/JavascriptModulesPlugin.js +68 -27
- package/lib/javascript/JavascriptParser.js +136 -81
- package/lib/javascript/JavascriptParserHelpers.js +41 -41
- package/lib/javascript/StartupHelpers.js +17 -17
- package/lib/json/JsonGenerator.js +4 -2
- package/lib/json/JsonModulesPlugin.js +2 -2
- package/lib/json/JsonParser.js +1 -1
- package/lib/library/AbstractLibraryPlugin.js +6 -2
- package/lib/library/AssignLibraryPlugin.js +21 -6
- package/lib/library/EnableLibraryPlugin.js +23 -3
- package/lib/library/ModuleLibraryPlugin.js +4 -1
- package/lib/library/UmdLibraryPlugin.js +15 -6
- package/lib/logging/createConsoleLogger.js +3 -3
- package/lib/logging/runtime.js +9 -9
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +4 -22
- package/lib/node/RequireChunkLoadingRuntimeModule.js +4 -22
- package/lib/node/nodeConsole.js +4 -2
- package/lib/optimize/AggressiveMergingPlugin.js +45 -46
- package/lib/optimize/AggressiveSplittingPlugin.js +13 -12
- package/lib/optimize/ConcatenatedModule.js +227 -57
- package/lib/optimize/EnsureChunkConditionsPlugin.js +58 -58
- package/lib/optimize/FlagIncludedChunksPlugin.js +3 -1
- package/lib/optimize/InnerGraph.js +115 -112
- package/lib/optimize/InnerGraphPlugin.js +2 -2
- package/lib/optimize/LimitChunkCountPlugin.js +4 -2
- package/lib/optimize/MangleExportsPlugin.js +4 -3
- package/lib/optimize/MergeDuplicateChunksPlugin.js +80 -81
- package/lib/optimize/MinChunkSizePlugin.js +6 -3
- package/lib/optimize/ModuleConcatenationPlugin.js +31 -22
- package/lib/optimize/RealContentHashPlugin.js +26 -20
- package/lib/optimize/RemoveEmptyChunksPlugin.js +2 -1
- package/lib/optimize/RemoveParentModulesPlugin.js +1 -0
- package/lib/optimize/SideEffectsFlagPlugin.js +6 -3
- package/lib/optimize/SplitChunksPlugin.js +16 -13
- package/lib/rules/BasicEffectRulePlugin.js +4 -2
- package/lib/rules/BasicMatcherRulePlugin.js +3 -1
- package/lib/rules/ObjectMatcherRulePlugin.js +3 -1
- package/lib/rules/RuleSetCompiler.js +7 -4
- package/lib/rules/UseEffectRulePlugin.js +3 -1
- package/lib/runtime/AsyncModuleRuntimeModule.js +64 -9
- package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +1 -1
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +214 -0
- package/lib/runtime/RuntimeIdRuntimeModule.js +2 -1
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +8 -7
- package/lib/schemes/DataUriPlugin.js +3 -1
- package/lib/schemes/FileUriPlugin.js +1 -1
- package/lib/schemes/HttpUriPlugin.js +27 -19
- package/lib/schemes/VirtualUrlPlugin.js +222 -0
- package/lib/serialization/AggregateErrorSerializer.js +1 -1
- package/lib/serialization/BinaryMiddleware.js +5 -4
- package/lib/serialization/FileMiddleware.js +7 -4
- package/lib/serialization/ObjectMiddleware.js +14 -8
- package/lib/serialization/Serializer.js +5 -3
- package/lib/serialization/SerializerMiddleware.js +2 -0
- package/lib/sharing/ConsumeSharedModule.js +1 -1
- package/lib/sharing/ConsumeSharedPlugin.js +3 -3
- package/lib/sharing/ConsumeSharedRuntimeModule.js +2 -2
- package/lib/sharing/ProvideSharedModule.js +1 -1
- package/lib/sharing/ProvideSharedPlugin.js +6 -3
- package/lib/sharing/SharePlugin.js +2 -1
- package/lib/sharing/ShareRuntimeModule.js +3 -5
- package/lib/sharing/utils.js +34 -34
- package/lib/stats/DefaultStatsFactoryPlugin.js +49 -46
- package/lib/stats/DefaultStatsPresetPlugin.js +4 -2
- package/lib/stats/DefaultStatsPrinterPlugin.js +28 -22
- package/lib/stats/StatsFactory.js +4 -2
- package/lib/stats/StatsPrinter.js +3 -2
- package/lib/url/URLParserPlugin.js +266 -0
- package/lib/util/ArrayQueue.js +1 -1
- package/lib/util/AsyncQueue.js +1 -1
- package/lib/util/Hash.js +2 -0
- package/lib/util/IterableHelpers.js +1 -1
- package/lib/util/LazyBucketSortedSet.js +2 -1
- package/lib/util/LazySet.js +11 -6
- package/lib/util/ParallelismFactorCalculator.js +1 -1
- package/lib/util/SetHelpers.js +3 -3
- package/lib/util/SortableSet.js +2 -2
- package/lib/util/StackedCacheMap.js +3 -1
- package/lib/util/StackedMap.js +2 -2
- package/lib/util/StringXor.js +1 -0
- package/lib/util/TupleSet.js +1 -0
- package/lib/util/URLAbsoluteSpecifier.js +1 -1
- package/lib/util/cleverMerge.js +12 -8
- package/lib/util/comparators.js +154 -127
- package/lib/util/compileBooleanMatcher.js +8 -3
- package/lib/util/concatenate.js +8 -7
- package/lib/util/conventions.js +72 -73
- package/lib/util/create-schema-validation.js +2 -1
- package/lib/util/createHash.js +10 -4
- package/lib/util/deprecation.js +69 -66
- package/lib/util/deterministicGrouping.js +4 -2
- package/lib/util/extractUrlAndGlobal.js +1 -1
- package/lib/util/findGraphRoots.js +2 -2
- package/lib/util/fs.js +30 -23
- package/lib/util/hash/md4.js +2 -2
- package/lib/util/hash/wasm-hash.js +4 -2
- package/lib/util/identifier.js +13 -12
- package/lib/util/internalSerializables.js +2 -0
- package/lib/util/magicComment.js +5 -5
- package/lib/util/processAsyncTree.js +1 -1
- package/lib/util/propertyAccess.js +1 -1
- package/lib/util/propertyName.js +1 -1
- package/lib/util/registerExternalSerializer.js +1 -2
- package/lib/util/removeBOM.js +1 -1
- package/lib/util/runtime.js +29 -21
- package/lib/util/semver.js +1 -1
- package/lib/util/serialization.js +3 -0
- package/lib/util/source.js +3 -2
- package/lib/validateSchema.js +1 -0
- package/lib/wasm/EnableWasmLoadingPlugin.js +6 -3
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +4 -1
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +46 -49
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +2 -2
- package/lib/wasm-sync/WebAssemblyGenerator.js +2 -3
- package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +3 -2
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +3 -0
- package/lib/wasm-sync/WebAssemblyUtils.js +1 -1
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +4 -22
- package/lib/webpack.js +4 -5
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +1 -0
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +6 -24
- package/lib/webworker/WebWorkerTemplatePlugin.js +1 -0
- package/package.json +121 -114
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +17 -0
- package/schemas/plugins/schemes/VirtualUrlPlugin.check.d.ts +7 -0
- package/schemas/plugins/schemes/VirtualUrlPlugin.check.js +6 -0
- package/schemas/plugins/schemes/VirtualUrlPlugin.json +77 -0
- package/types.d.ts +1261 -366
|
@@ -15,13 +15,14 @@ const {
|
|
|
15
15
|
/** @typedef {import("./optimize/ConcatenatedModule").ModuleInfo} ModuleInfo */
|
|
16
16
|
|
|
17
17
|
const MODULE_REFERENCE_REGEXP =
|
|
18
|
-
/^__WEBPACK_MODULE_REFERENCE__(\d+)_([\da-f]+|ns)(_call)?(_directImport)?(?:_asiSafe(\d))?__$/;
|
|
18
|
+
/^__WEBPACK_MODULE_REFERENCE__(\d+)_([\da-f]+|ns)(_call)?(_directImport)?(_deferredImport)?(?:_asiSafe(\d))?__$/;
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
21
|
* @typedef {object} ModuleReferenceOptions
|
|
22
22
|
* @property {string[]} ids the properties/exports of the module
|
|
23
23
|
* @property {boolean} call true, when this referenced export is called
|
|
24
24
|
* @property {boolean} directImport true, when this referenced export is directly imported (not via property access)
|
|
25
|
+
* @property {boolean} deferredImport true, when this referenced export is deferred
|
|
25
26
|
* @property {boolean | undefined} asiSafe if the position is ASI safe or unknown
|
|
26
27
|
*/
|
|
27
28
|
|
|
@@ -90,21 +91,28 @@ class ConcatenationScope {
|
|
|
90
91
|
*/
|
|
91
92
|
createModuleReference(
|
|
92
93
|
module,
|
|
93
|
-
{
|
|
94
|
+
{
|
|
95
|
+
ids = undefined,
|
|
96
|
+
call = false,
|
|
97
|
+
directImport = false,
|
|
98
|
+
deferredImport = false,
|
|
99
|
+
asiSafe = false
|
|
100
|
+
}
|
|
94
101
|
) {
|
|
95
102
|
const info = /** @type {ModuleInfo} */ (this._modulesMap.get(module));
|
|
96
103
|
const callFlag = call ? "_call" : "";
|
|
97
104
|
const directImportFlag = directImport ? "_directImport" : "";
|
|
105
|
+
const deferredImportFlag = deferredImport ? "_deferredImport" : "";
|
|
98
106
|
const asiSafeFlag = asiSafe
|
|
99
107
|
? "_asiSafe1"
|
|
100
108
|
: asiSafe === false
|
|
101
109
|
? "_asiSafe0"
|
|
102
110
|
: "";
|
|
103
111
|
const exportData = ids
|
|
104
|
-
? Buffer.from(JSON.stringify(ids), "
|
|
112
|
+
? Buffer.from(JSON.stringify(ids), "utf8").toString("hex")
|
|
105
113
|
: "ns";
|
|
106
114
|
// a "._" is appended to allow "delete ...", which would cause a SyntaxError in strict mode
|
|
107
|
-
return `__WEBPACK_MODULE_REFERENCE__${info.index}_${exportData}${callFlag}${directImportFlag}${asiSafeFlag}__._`;
|
|
115
|
+
return `__WEBPACK_MODULE_REFERENCE__${info.index}_${exportData}${callFlag}${directImportFlag}${deferredImportFlag}${asiSafeFlag}__._`;
|
|
108
116
|
}
|
|
109
117
|
|
|
110
118
|
/**
|
|
@@ -123,15 +131,16 @@ class ConcatenationScope {
|
|
|
123
131
|
const match = MODULE_REFERENCE_REGEXP.exec(name);
|
|
124
132
|
if (!match) return null;
|
|
125
133
|
const index = Number(match[1]);
|
|
126
|
-
const asiSafe = match[
|
|
134
|
+
const asiSafe = match[6];
|
|
127
135
|
return {
|
|
128
136
|
index,
|
|
129
137
|
ids:
|
|
130
138
|
match[2] === "ns"
|
|
131
139
|
? []
|
|
132
|
-
: JSON.parse(Buffer.from(match[2], "hex").toString("
|
|
140
|
+
: JSON.parse(Buffer.from(match[2], "hex").toString("utf8")),
|
|
133
141
|
call: Boolean(match[3]),
|
|
134
142
|
directImport: Boolean(match[4]),
|
|
143
|
+
deferredImport: Boolean(match[5]),
|
|
135
144
|
asiSafe: asiSafe ? asiSafe === "1" : undefined
|
|
136
145
|
};
|
|
137
146
|
}
|
package/lib/ConstPlugin.js
CHANGED
|
@@ -68,6 +68,7 @@ const collectDeclaration = (declarations, pattern) => {
|
|
|
68
68
|
* @returns {Array<string>} hoisted declarations
|
|
69
69
|
*/
|
|
70
70
|
const getHoistedDeclarations = (branch, includeFunctionDeclarations) => {
|
|
71
|
+
/** @type {Set<string>} */
|
|
71
72
|
const declarations = new Set();
|
|
72
73
|
/** @type {Array<Statement | null | undefined>} */
|
|
73
74
|
const stack = [branch];
|
|
@@ -129,7 +130,7 @@ const getHoistedDeclarations = (branch, includeFunctionDeclarations) => {
|
|
|
129
130
|
break;
|
|
130
131
|
}
|
|
131
132
|
}
|
|
132
|
-
return
|
|
133
|
+
return [...declarations];
|
|
133
134
|
};
|
|
134
135
|
|
|
135
136
|
const PLUGIN_NAME = "ConstPlugin";
|
|
@@ -159,7 +160,7 @@ class ConstPlugin {
|
|
|
159
160
|
* @param {JavascriptParser} parser the parser
|
|
160
161
|
*/
|
|
161
162
|
const handler = parser => {
|
|
162
|
-
parser.hooks.terminate.tap(PLUGIN_NAME,
|
|
163
|
+
parser.hooks.terminate.tap(PLUGIN_NAME, _statement => true);
|
|
163
164
|
parser.hooks.statementIf.tap(PLUGIN_NAME, statement => {
|
|
164
165
|
if (parser.scope.isAsmJs) return;
|
|
165
166
|
const param = parser.evaluateExpression(statement.test);
|
|
@@ -179,53 +180,22 @@ class ConstPlugin {
|
|
|
179
180
|
? statement.alternate
|
|
180
181
|
: statement.consequent;
|
|
181
182
|
if (branchToRemove) {
|
|
182
|
-
|
|
183
|
-
// must be collected.
|
|
184
|
-
//
|
|
185
|
-
// Given the following code:
|
|
186
|
-
//
|
|
187
|
-
// if (true) f() else g()
|
|
188
|
-
// if (false) {
|
|
189
|
-
// function f() {}
|
|
190
|
-
// const g = function g() {}
|
|
191
|
-
// if (someTest) {
|
|
192
|
-
// let a = 1
|
|
193
|
-
// var x, {y, z} = obj
|
|
194
|
-
// }
|
|
195
|
-
// } else {
|
|
196
|
-
// …
|
|
197
|
-
// }
|
|
198
|
-
//
|
|
199
|
-
// the generated code is:
|
|
200
|
-
//
|
|
201
|
-
// if (true) f() else {}
|
|
202
|
-
// if (false) {
|
|
203
|
-
// var f, x, y, z; (in loose mode)
|
|
204
|
-
// var x, y, z; (in strict mode)
|
|
205
|
-
// } else {
|
|
206
|
-
// …
|
|
207
|
-
// }
|
|
208
|
-
//
|
|
209
|
-
// NOTE: When code runs in strict mode, `var` declarations
|
|
210
|
-
// are hoisted but `function` declarations don't.
|
|
211
|
-
//
|
|
212
|
-
const declarations = parser.scope.isStrict
|
|
213
|
-
? getHoistedDeclarations(branchToRemove, false)
|
|
214
|
-
: getHoistedDeclarations(branchToRemove, true);
|
|
215
|
-
const replacement =
|
|
216
|
-
declarations.length > 0
|
|
217
|
-
? `{ var ${declarations.join(", ")}; }`
|
|
218
|
-
: "{}";
|
|
219
|
-
const dep = new ConstDependency(
|
|
220
|
-
replacement,
|
|
221
|
-
/** @type {Range} */ (branchToRemove.range)
|
|
222
|
-
);
|
|
223
|
-
dep.loc = /** @type {SourceLocation} */ (branchToRemove.loc);
|
|
224
|
-
parser.state.module.addPresentationalDependency(dep);
|
|
183
|
+
this.eliminateUnusedStatement(parser, branchToRemove);
|
|
225
184
|
}
|
|
226
185
|
return bool;
|
|
227
186
|
}
|
|
228
187
|
});
|
|
188
|
+
parser.hooks.unusedStatement.tap(PLUGIN_NAME, statement => {
|
|
189
|
+
if (
|
|
190
|
+
parser.scope.isAsmJs ||
|
|
191
|
+
// Check top level scope here again
|
|
192
|
+
parser.scope.topLevelScope === true
|
|
193
|
+
) {
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
this.eliminateUnusedStatement(parser, statement);
|
|
197
|
+
return true;
|
|
198
|
+
});
|
|
229
199
|
parser.hooks.expressionConditionalOperator.tap(
|
|
230
200
|
PLUGIN_NAME,
|
|
231
201
|
expression => {
|
|
@@ -534,6 +504,56 @@ class ConstPlugin {
|
|
|
534
504
|
}
|
|
535
505
|
);
|
|
536
506
|
}
|
|
507
|
+
|
|
508
|
+
/**
|
|
509
|
+
* Eliminate an unused statement.
|
|
510
|
+
* @param {JavascriptParser} parser the parser
|
|
511
|
+
* @param {Statement} statement the statement to remove
|
|
512
|
+
* @returns {void}
|
|
513
|
+
*/
|
|
514
|
+
eliminateUnusedStatement(parser, statement) {
|
|
515
|
+
// Before removing the unused branch, the hoisted declarations
|
|
516
|
+
// must be collected.
|
|
517
|
+
//
|
|
518
|
+
// Given the following code:
|
|
519
|
+
//
|
|
520
|
+
// if (true) f() else g()
|
|
521
|
+
// if (false) {
|
|
522
|
+
// function f() {}
|
|
523
|
+
// const g = function g() {}
|
|
524
|
+
// if (someTest) {
|
|
525
|
+
// let a = 1
|
|
526
|
+
// var x, {y, z} = obj
|
|
527
|
+
// }
|
|
528
|
+
// } else {
|
|
529
|
+
// …
|
|
530
|
+
// }
|
|
531
|
+
//
|
|
532
|
+
// the generated code is:
|
|
533
|
+
//
|
|
534
|
+
// if (true) f() else {}
|
|
535
|
+
// if (false) {
|
|
536
|
+
// var f, x, y, z; (in loose mode)
|
|
537
|
+
// var x, y, z; (in strict mode)
|
|
538
|
+
// } else {
|
|
539
|
+
// …
|
|
540
|
+
// }
|
|
541
|
+
//
|
|
542
|
+
// NOTE: When code runs in strict mode, `var` declarations
|
|
543
|
+
// are hoisted but `function` declarations don't.
|
|
544
|
+
//
|
|
545
|
+
const declarations = parser.scope.isStrict
|
|
546
|
+
? getHoistedDeclarations(statement, false)
|
|
547
|
+
: getHoistedDeclarations(statement, true);
|
|
548
|
+
const replacement =
|
|
549
|
+
declarations.length > 0 ? `{ var ${declarations.join(", ")}; }` : "{}";
|
|
550
|
+
const dep = new ConstDependency(
|
|
551
|
+
`// removed by dead control flow\n${replacement}`,
|
|
552
|
+
/** @type {Range} */ (statement.range)
|
|
553
|
+
);
|
|
554
|
+
dep.loc = /** @type {SourceLocation} */ (statement.loc);
|
|
555
|
+
parser.state.module.addPresentationalDependency(dep);
|
|
556
|
+
}
|
|
537
557
|
}
|
|
538
558
|
|
|
539
559
|
module.exports = ConstPlugin;
|
package/lib/ContextModule.js
CHANGED
|
@@ -16,15 +16,15 @@ const Template = require("./Template");
|
|
|
16
16
|
const WebpackError = require("./WebpackError");
|
|
17
17
|
const {
|
|
18
18
|
compareLocations,
|
|
19
|
-
|
|
19
|
+
compareModulesById,
|
|
20
20
|
compareSelect,
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
concatComparators,
|
|
22
|
+
keepOriginalOrder
|
|
23
23
|
} = require("./util/comparators");
|
|
24
24
|
const {
|
|
25
25
|
contextify,
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
makePathsRelative,
|
|
27
|
+
parseResource
|
|
28
28
|
} = require("./util/identifier");
|
|
29
29
|
const makeSerializable = require("./util/makeSerializable");
|
|
30
30
|
|
|
@@ -412,8 +412,9 @@ class ContextModule extends Module {
|
|
|
412
412
|
const buildInfo = /** @type {BuildInfo} */ (this.buildInfo);
|
|
413
413
|
|
|
414
414
|
// always build when we have no snapshot and context
|
|
415
|
-
if (!buildInfo.snapshot)
|
|
415
|
+
if (!buildInfo.snapshot) {
|
|
416
416
|
return callback(null, Boolean(this.context || this.options.resource));
|
|
417
|
+
}
|
|
417
418
|
|
|
418
419
|
fileSystemInfo.checkSnapshotValid(buildInfo.snapshot, (err, valid) => {
|
|
419
420
|
callback(err, !valid);
|
|
@@ -996,10 +997,11 @@ module.exports = webpackAsyncContext;`;
|
|
|
996
997
|
if (hasFakeMap) {
|
|
997
998
|
arrayStart.push(fakeMap[moduleId]);
|
|
998
999
|
}
|
|
999
|
-
map[item.userRequest] =
|
|
1000
|
-
|
|
1000
|
+
map[item.userRequest] = [
|
|
1001
|
+
...arrayStart,
|
|
1002
|
+
.../** @type {Chunk[]} */
|
|
1001
1003
|
(item.chunks).map(chunk => /** @type {ChunkId} */ (chunk.id))
|
|
1002
|
-
|
|
1004
|
+
];
|
|
1003
1005
|
}
|
|
1004
1006
|
}
|
|
1005
1007
|
|
|
@@ -1186,11 +1188,13 @@ module.exports = webpackEmptyAsyncContext;`;
|
|
|
1186
1188
|
const set = new Set();
|
|
1187
1189
|
const allDeps =
|
|
1188
1190
|
this.dependencies.length > 0
|
|
1189
|
-
? /** @type {ContextElementDependency[]} */
|
|
1191
|
+
? /** @type {ContextElementDependency[]} */ [...this.dependencies]
|
|
1190
1192
|
: [];
|
|
1191
|
-
for (const block of this.blocks)
|
|
1192
|
-
for (const dep of block.dependencies)
|
|
1193
|
+
for (const block of this.blocks) {
|
|
1194
|
+
for (const dep of block.dependencies) {
|
|
1193
1195
|
allDeps.push(/** @type {ContextElementDependency} */ (dep));
|
|
1196
|
+
}
|
|
1197
|
+
}
|
|
1194
1198
|
set.add(RuntimeGlobals.module);
|
|
1195
1199
|
set.add(RuntimeGlobals.hasOwnProperty);
|
|
1196
1200
|
if (allDeps.length > 0) {
|
|
@@ -344,14 +344,15 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
|
|
|
344
344
|
const processedFiles = cmf.hooks.contextModuleFiles.call(
|
|
345
345
|
/** @type {string[]} */ (files).map(file => file.normalize("NFC"))
|
|
346
346
|
);
|
|
347
|
-
if (!processedFiles || processedFiles.length === 0)
|
|
347
|
+
if (!processedFiles || processedFiles.length === 0) {
|
|
348
348
|
return callback(null, []);
|
|
349
|
+
}
|
|
349
350
|
asyncLib.map(
|
|
350
351
|
processedFiles.filter(p => p.indexOf(".") !== 0),
|
|
351
352
|
(segment, callback) => {
|
|
352
353
|
const subResource = join(fs, directory, segment);
|
|
353
354
|
|
|
354
|
-
if (!exclude || !
|
|
355
|
+
if (!exclude || !exclude.test(subResource)) {
|
|
355
356
|
fs.stat(subResource, (err, _stat) => {
|
|
356
357
|
if (err) {
|
|
357
358
|
if (err.code === "ENOENT") {
|
|
@@ -369,7 +370,7 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
|
|
|
369
370
|
addSubDirectory(ctx, subResource, callback);
|
|
370
371
|
} else if (
|
|
371
372
|
stat.isFile() &&
|
|
372
|
-
(!include ||
|
|
373
|
+
(!include || include.test(subResource))
|
|
373
374
|
) {
|
|
374
375
|
/** @type {{ context: string, request: string }} */
|
|
375
376
|
const obj = {
|
|
@@ -131,7 +131,8 @@ class ContextReplacementPlugin {
|
|
|
131
131
|
result.resource = newContentResource;
|
|
132
132
|
} else {
|
|
133
133
|
result.resource = join(
|
|
134
|
-
/** @type {InputFileSystem} */
|
|
134
|
+
/** @type {InputFileSystem} */
|
|
135
|
+
(compiler.inputFileSystem),
|
|
135
136
|
result.resource,
|
|
136
137
|
newContentResource
|
|
137
138
|
);
|
|
@@ -159,7 +160,8 @@ class ContextReplacementPlugin {
|
|
|
159
160
|
) {
|
|
160
161
|
// When the function changed it to an relative path
|
|
161
162
|
result.resource = join(
|
|
162
|
-
/** @type {InputFileSystem} */
|
|
163
|
+
/** @type {InputFileSystem} */
|
|
164
|
+
(compiler.inputFileSystem),
|
|
163
165
|
origResource,
|
|
164
166
|
result.resource
|
|
165
167
|
);
|
package/lib/CssModule.js
CHANGED
|
@@ -18,9 +18,9 @@ const makeSerializable = require("./util/makeSerializable");
|
|
|
18
18
|
/** @typedef {string | undefined} Supports */
|
|
19
19
|
/** @typedef {string | undefined} Media */
|
|
20
20
|
/** @typedef {[CssLayer, Supports, Media]} InheritanceItem */
|
|
21
|
-
/** @typedef {
|
|
21
|
+
/** @typedef {InheritanceItem[]} Inheritance */
|
|
22
22
|
|
|
23
|
-
/** @typedef {NormalModuleCreateData & { cssLayer: CssLayer, supports: Supports, media: Media, inheritance
|
|
23
|
+
/** @typedef {NormalModuleCreateData & { cssLayer: CssLayer, supports: Supports, media: Media, inheritance?: Inheritance }} CSSModuleCreateData */
|
|
24
24
|
|
|
25
25
|
class CssModule extends NormalModule {
|
|
26
26
|
/**
|
|
@@ -158,7 +158,6 @@ class CssModule extends NormalModule {
|
|
|
158
158
|
|
|
159
159
|
/**
|
|
160
160
|
* @param {ObjectDeserializerContext} context context
|
|
161
|
-
* @returns {TODO} Module
|
|
162
161
|
*/
|
|
163
162
|
deserialize(context) {
|
|
164
163
|
const { read } = context;
|
package/lib/DefinePlugin.js
CHANGED
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
|
|
8
8
|
const {
|
|
9
9
|
JAVASCRIPT_MODULE_TYPE_AUTO,
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
JAVASCRIPT_MODULE_TYPE_DYNAMIC,
|
|
11
|
+
JAVASCRIPT_MODULE_TYPE_ESM
|
|
12
12
|
} = require("./ModuleTypeConstants");
|
|
13
13
|
const RuntimeGlobals = require("./RuntimeGlobals");
|
|
14
14
|
const WebpackError = require("./WebpackError");
|
|
@@ -356,6 +356,16 @@ class DefinePlugin {
|
|
|
356
356
|
*/
|
|
357
357
|
apply(compiler) {
|
|
358
358
|
const definitions = this.definitions;
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* @type {Map<string, Set<string>>}
|
|
362
|
+
*/
|
|
363
|
+
const finalByNestedKey = new Map();
|
|
364
|
+
/**
|
|
365
|
+
* @type {Map<string, Set<string>>}
|
|
366
|
+
*/
|
|
367
|
+
const nestedByFinalKey = new Map();
|
|
368
|
+
|
|
359
369
|
compiler.hooks.compilation.tap(
|
|
360
370
|
PLUGIN_NAME,
|
|
361
371
|
(compilation, { normalModuleFactory }) => {
|
|
@@ -381,6 +391,7 @@ class DefinePlugin {
|
|
|
381
391
|
* @returns {void}
|
|
382
392
|
*/
|
|
383
393
|
const handler = parser => {
|
|
394
|
+
const hooked = new Set();
|
|
384
395
|
const mainValue =
|
|
385
396
|
/** @type {ValueCacheVersion} */
|
|
386
397
|
(compilation.valueCacheVersions.get(VALUE_DEP_MAIN));
|
|
@@ -388,8 +399,9 @@ class DefinePlugin {
|
|
|
388
399
|
const buildInfo = /** @type {BuildInfo} */ (
|
|
389
400
|
parser.state.module.buildInfo
|
|
390
401
|
);
|
|
391
|
-
if (!buildInfo.valueDependencies)
|
|
402
|
+
if (!buildInfo.valueDependencies) {
|
|
392
403
|
buildInfo.valueDependencies = new Map();
|
|
404
|
+
}
|
|
393
405
|
buildInfo.valueDependencies.set(VALUE_DEP_MAIN, mainValue);
|
|
394
406
|
});
|
|
395
407
|
|
|
@@ -469,6 +481,61 @@ class DefinePlugin {
|
|
|
469
481
|
return true;
|
|
470
482
|
});
|
|
471
483
|
}
|
|
484
|
+
if (prefix === "") {
|
|
485
|
+
const final = splittedKey[splittedKey.length - 1];
|
|
486
|
+
const nestedSet = nestedByFinalKey.get(final);
|
|
487
|
+
if (!nestedSet || nestedSet.size <= 0) return;
|
|
488
|
+
for (const nested of /** @type {Set<string>} */ (nestedSet)) {
|
|
489
|
+
if (nested && !hooked.has(nested)) {
|
|
490
|
+
// only detect the same nested key once
|
|
491
|
+
hooked.add(nested);
|
|
492
|
+
parser.hooks.expression.for(nested).tap(
|
|
493
|
+
{
|
|
494
|
+
name: PLUGIN_NAME,
|
|
495
|
+
// why 100? Ensures it runs after object define
|
|
496
|
+
stage: 100
|
|
497
|
+
},
|
|
498
|
+
expr => {
|
|
499
|
+
const destructed =
|
|
500
|
+
parser.destructuringAssignmentPropertiesFor(expr);
|
|
501
|
+
if (destructed === undefined) {
|
|
502
|
+
return;
|
|
503
|
+
}
|
|
504
|
+
/** @type {Record<string, CodeValue>} */
|
|
505
|
+
const obj = {};
|
|
506
|
+
const finalSet = finalByNestedKey.get(nested);
|
|
507
|
+
for (const { id } of destructed) {
|
|
508
|
+
const fullKey = `${nested}.${id}`;
|
|
509
|
+
if (
|
|
510
|
+
!finalSet ||
|
|
511
|
+
!finalSet.has(id) ||
|
|
512
|
+
!definitions[fullKey]
|
|
513
|
+
) {
|
|
514
|
+
return;
|
|
515
|
+
}
|
|
516
|
+
obj[id] = definitions[fullKey];
|
|
517
|
+
}
|
|
518
|
+
let strCode = stringifyObj(
|
|
519
|
+
obj,
|
|
520
|
+
parser,
|
|
521
|
+
compilation.valueCacheVersions,
|
|
522
|
+
key,
|
|
523
|
+
runtimeTemplate,
|
|
524
|
+
logger,
|
|
525
|
+
!parser.isAsiPosition(
|
|
526
|
+
/** @type {Range} */ (expr.range)[0]
|
|
527
|
+
),
|
|
528
|
+
getObjKeys(destructed)
|
|
529
|
+
);
|
|
530
|
+
if (parser.scope.inShorthand) {
|
|
531
|
+
strCode = `${parser.scope.inShorthand}:${strCode}`;
|
|
532
|
+
}
|
|
533
|
+
return toConstantDependency(parser, strCode)(expr);
|
|
534
|
+
}
|
|
535
|
+
);
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
}
|
|
472
539
|
};
|
|
473
540
|
|
|
474
541
|
/**
|
|
@@ -707,6 +774,46 @@ class DefinePlugin {
|
|
|
707
774
|
}
|
|
708
775
|
};
|
|
709
776
|
|
|
777
|
+
/**
|
|
778
|
+
* @param {Record<string, CodeValue>} definitions Definitions map
|
|
779
|
+
* @returns {void}
|
|
780
|
+
*/
|
|
781
|
+
const walkDefinitionsForKeys = definitions => {
|
|
782
|
+
/**
|
|
783
|
+
* @param {Map<string, Set<string>>} map Map
|
|
784
|
+
* @param {string} key key
|
|
785
|
+
* @param {string} value v
|
|
786
|
+
* @returns {void}
|
|
787
|
+
*/
|
|
788
|
+
const addToMap = (map, key, value) => {
|
|
789
|
+
if (map.has(key)) {
|
|
790
|
+
/** @type {Set<string>} */
|
|
791
|
+
(map.get(key)).add(value);
|
|
792
|
+
} else {
|
|
793
|
+
map.set(key, new Set([value]));
|
|
794
|
+
}
|
|
795
|
+
};
|
|
796
|
+
for (const key of Object.keys(definitions)) {
|
|
797
|
+
const code = definitions[key];
|
|
798
|
+
if (
|
|
799
|
+
!code ||
|
|
800
|
+
typeof code === "object" ||
|
|
801
|
+
TYPEOF_OPERATOR_REGEXP.test(key)
|
|
802
|
+
) {
|
|
803
|
+
continue;
|
|
804
|
+
}
|
|
805
|
+
const idx = key.lastIndexOf(".");
|
|
806
|
+
if (idx <= 0 || idx >= key.length - 1) {
|
|
807
|
+
continue;
|
|
808
|
+
}
|
|
809
|
+
const nested = key.slice(0, idx);
|
|
810
|
+
const final = key.slice(idx + 1);
|
|
811
|
+
addToMap(finalByNestedKey, nested, final);
|
|
812
|
+
addToMap(nestedByFinalKey, final, nested);
|
|
813
|
+
}
|
|
814
|
+
};
|
|
815
|
+
|
|
816
|
+
walkDefinitionsForKeys(definitions);
|
|
710
817
|
walkDefinitionsForValues(definitions, "");
|
|
711
818
|
|
|
712
819
|
compilation.valueCacheVersions.set(
|
|
@@ -717,4 +824,5 @@ class DefinePlugin {
|
|
|
717
824
|
);
|
|
718
825
|
}
|
|
719
826
|
}
|
|
827
|
+
|
|
720
828
|
module.exports = DefinePlugin;
|
|
@@ -25,6 +25,8 @@ const DelegatedModule = require("./DelegatedModule");
|
|
|
25
25
|
* @property {AssociatedObjectForCache=} associatedObjectForCache object for caching
|
|
26
26
|
*/
|
|
27
27
|
|
|
28
|
+
const PLUGIN_NAME = "DelegatedModuleFactoryPlugin";
|
|
29
|
+
|
|
28
30
|
class DelegatedModuleFactoryPlugin {
|
|
29
31
|
/**
|
|
30
32
|
* @param {Options} options options
|
|
@@ -43,7 +45,7 @@ class DelegatedModuleFactoryPlugin {
|
|
|
43
45
|
const scope = this.options.scope;
|
|
44
46
|
if (scope) {
|
|
45
47
|
normalModuleFactory.hooks.factorize.tapAsync(
|
|
46
|
-
|
|
48
|
+
PLUGIN_NAME,
|
|
47
49
|
(data, callback) => {
|
|
48
50
|
const [dependency] = data.dependencies;
|
|
49
51
|
const { request } = dependency;
|
|
@@ -90,25 +92,23 @@ class DelegatedModuleFactoryPlugin {
|
|
|
90
92
|
}
|
|
91
93
|
);
|
|
92
94
|
} else {
|
|
93
|
-
normalModuleFactory.hooks.module.tap(
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
module
|
|
106
|
-
);
|
|
107
|
-
}
|
|
108
|
-
return module;
|
|
95
|
+
normalModuleFactory.hooks.module.tap(PLUGIN_NAME, module => {
|
|
96
|
+
const request = module.libIdent(this.options);
|
|
97
|
+
if (request && request in this.options.content) {
|
|
98
|
+
const resolved = this.options.content[request];
|
|
99
|
+
return new DelegatedModule(
|
|
100
|
+
this.options.source,
|
|
101
|
+
resolved,
|
|
102
|
+
/** @type {DelegatedModuleType} */
|
|
103
|
+
(this.options.type),
|
|
104
|
+
request,
|
|
105
|
+
module
|
|
106
|
+
);
|
|
109
107
|
}
|
|
110
|
-
|
|
108
|
+
return module;
|
|
109
|
+
});
|
|
111
110
|
}
|
|
112
111
|
}
|
|
113
112
|
}
|
|
113
|
+
|
|
114
114
|
module.exports = DelegatedModuleFactoryPlugin;
|
package/lib/Dependency.js
CHANGED
|
@@ -101,7 +101,10 @@ class Dependency {
|
|
|
101
101
|
/** @type {boolean} */
|
|
102
102
|
this.weak = false;
|
|
103
103
|
// TODO check if this can be moved into ModuleDependency
|
|
104
|
-
/** @type {boolean} */
|
|
104
|
+
/** @type {boolean | undefined} */
|
|
105
|
+
this.defer = false;
|
|
106
|
+
// TODO check if this can be moved into ModuleDependency
|
|
107
|
+
/** @type {boolean | undefined} */
|
|
105
108
|
this.optional = false;
|
|
106
109
|
this._locSL = 0;
|
|
107
110
|
this._locSC = 0;
|
|
@@ -131,23 +134,22 @@ class Dependency {
|
|
|
131
134
|
*/
|
|
132
135
|
get loc() {
|
|
133
136
|
if (this._loc !== undefined) return this._loc;
|
|
137
|
+
|
|
134
138
|
/** @type {SyntheticDependencyLocation & RealDependencyLocation} */
|
|
135
|
-
const loc = {
|
|
136
|
-
|
|
137
|
-
end: { line: 0, column: 0 },
|
|
138
|
-
name: "",
|
|
139
|
-
index: -1
|
|
140
|
-
};
|
|
139
|
+
const loc = {};
|
|
140
|
+
|
|
141
141
|
if (this._locSL > 0) {
|
|
142
142
|
loc.start = { line: this._locSL, column: this._locSC };
|
|
143
143
|
}
|
|
144
144
|
if (this._locEL > 0) {
|
|
145
145
|
loc.end = { line: this._locEL, column: this._locEC };
|
|
146
146
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
147
|
+
if (this._locN !== undefined) {
|
|
148
|
+
loc.name = this._locN;
|
|
149
|
+
}
|
|
150
|
+
if (this._locI !== undefined) {
|
|
151
|
+
loc.index = this._locI;
|
|
152
|
+
}
|
|
151
153
|
|
|
152
154
|
return (this._loc = loc);
|
|
153
155
|
}
|
|
@@ -292,7 +294,7 @@ class Dependency {
|
|
|
292
294
|
|
|
293
295
|
/**
|
|
294
296
|
* @param {string} context context directory
|
|
295
|
-
* @returns {Module
|
|
297
|
+
* @returns {Module} ignored module
|
|
296
298
|
*/
|
|
297
299
|
createIgnoredModule(context) {
|
|
298
300
|
return getIgnoredModule();
|
|
@@ -310,6 +312,7 @@ class Dependency {
|
|
|
310
312
|
write(this._locEC);
|
|
311
313
|
write(this._locI);
|
|
312
314
|
write(this._locN);
|
|
315
|
+
write(this.defer);
|
|
313
316
|
}
|
|
314
317
|
|
|
315
318
|
/**
|
|
@@ -324,6 +327,7 @@ class Dependency {
|
|
|
324
327
|
this._locEC = read();
|
|
325
328
|
this._locI = read();
|
|
326
329
|
this._locN = read();
|
|
330
|
+
this.defer = read();
|
|
327
331
|
}
|
|
328
332
|
}
|
|
329
333
|
|
package/lib/DllEntryPlugin.js
CHANGED
|
@@ -10,8 +10,10 @@ const DllEntryDependency = require("./dependencies/DllEntryDependency");
|
|
|
10
10
|
const EntryDependency = require("./dependencies/EntryDependency");
|
|
11
11
|
|
|
12
12
|
/** @typedef {import("./Compiler")} Compiler */
|
|
13
|
+
/** @typedef {import("./Entrypoint").EntryOptions} EntryOptions */
|
|
14
|
+
|
|
13
15
|
/** @typedef {string[]} Entries */
|
|
14
|
-
/** @typedef {{ name: string
|
|
16
|
+
/** @typedef {EntryOptions & { name: string }} Options */
|
|
15
17
|
|
|
16
18
|
const PLUGIN_NAME = "DllEntryPlugin";
|
|
17
19
|
|
package/lib/DllPlugin.js
CHANGED
|
@@ -16,7 +16,7 @@ const createSchemaValidation = require("./util/create-schema-validation");
|
|
|
16
16
|
/** @typedef {import("./DllEntryPlugin").Options} Options */
|
|
17
17
|
|
|
18
18
|
const validate = createSchemaValidation(
|
|
19
|
-
require("../schemas/plugins/DllPlugin.check
|
|
19
|
+
require("../schemas/plugins/DllPlugin.check"),
|
|
20
20
|
() => require("../schemas/plugins/DllPlugin.json"),
|
|
21
21
|
{
|
|
22
22
|
name: "Dll Plugin",
|
|
@@ -48,10 +48,11 @@ class DllPlugin {
|
|
|
48
48
|
if (typeof entry !== "function") {
|
|
49
49
|
for (const name of Object.keys(entry)) {
|
|
50
50
|
/** @type {Options} */
|
|
51
|
-
const options = { name
|
|
51
|
+
const options = { name };
|
|
52
52
|
new DllEntryPlugin(
|
|
53
53
|
context,
|
|
54
|
-
/** @type {Entries} */
|
|
54
|
+
/** @type {Entries} */
|
|
55
|
+
(entry[name].import),
|
|
55
56
|
options
|
|
56
57
|
).apply(compiler);
|
|
57
58
|
}
|