webpack 5.59.0 → 5.71.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.
Potentially problematic release.
This version of webpack might be problematic. Click here for more details.
- package/README.md +1 -7
- package/hot/lazy-compilation-node.js +3 -1
- package/hot/poll.js +1 -1
- package/hot/signal.js +1 -1
- package/lib/APIPlugin.js +33 -0
- package/lib/BannerPlugin.js +10 -4
- package/lib/Cache.js +1 -1
- package/lib/CacheFacade.js +4 -11
- package/lib/Chunk.js +6 -3
- package/lib/ChunkGraph.js +1 -2
- package/lib/ChunkGroup.js +1 -1
- package/lib/CleanPlugin.js +81 -20
- package/lib/Compilation.js +179 -91
- package/lib/Compiler.js +86 -17
- package/lib/ConstPlugin.js +2 -2
- package/lib/ContextModule.js +142 -51
- package/lib/ContextModuleFactory.js +65 -25
- package/lib/DelegatedModule.js +1 -1
- package/lib/DelegatedModuleFactoryPlugin.js +1 -1
- package/lib/Dependency.js +17 -0
- package/lib/DependencyTemplate.js +9 -0
- package/lib/DependencyTemplates.js +1 -1
- package/lib/DllModule.js +1 -1
- package/lib/EntryOptionPlugin.js +2 -0
- package/lib/ErrorHelpers.js +2 -2
- package/lib/EvalDevToolModulePlugin.js +16 -1
- package/lib/EvalSourceMapDevToolPlugin.js +18 -1
- package/lib/ExportsInfo.js +4 -4
- package/lib/ExternalModule.js +94 -54
- package/lib/ExternalModuleFactoryPlugin.js +5 -5
- package/lib/FileSystemInfo.js +89 -44
- package/lib/Generator.js +3 -0
- package/lib/HookWebpackError.js +1 -1
- package/lib/HotModuleReplacementPlugin.js +3 -1
- package/lib/LoaderOptionsPlugin.js +1 -1
- package/lib/Module.js +27 -4
- package/lib/ModuleFilenameHelpers.js +8 -4
- package/lib/ModuleHashingError.js +29 -0
- package/lib/MultiCompiler.js +1 -1
- package/lib/MultiWatching.js +1 -1
- package/lib/NodeStuffPlugin.js +10 -0
- package/lib/NormalModule.js +41 -26
- package/lib/NormalModuleFactory.js +42 -37
- package/lib/ProgressPlugin.js +4 -5
- package/lib/RawModule.js +1 -1
- package/lib/RuntimeGlobals.js +29 -1
- package/lib/RuntimeModule.js +1 -1
- package/lib/RuntimePlugin.js +77 -1
- package/lib/RuntimeTemplate.js +114 -2
- package/lib/Template.js +2 -1
- package/lib/TemplatedPathPlugin.js +48 -23
- package/lib/WatchIgnorePlugin.js +19 -7
- package/lib/Watching.js +33 -19
- package/lib/WebpackOptionsApply.js +57 -11
- package/lib/asset/AssetGenerator.js +193 -63
- package/lib/asset/AssetModulesPlugin.js +3 -0
- package/lib/asset/RawDataUrlModule.js +148 -0
- package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -4
- package/lib/buildChunkGraph.js +36 -6
- package/lib/cache/PackFileCacheStrategy.js +7 -4
- package/lib/cache/ResolverCachePlugin.js +90 -29
- package/lib/cli.js +44 -3
- package/lib/config/browserslistTargetHandler.js +41 -6
- package/lib/config/defaults.js +115 -19
- package/lib/config/normalization.js +9 -0
- package/lib/config/target.js +10 -0
- package/lib/container/ContainerEntryModule.js +8 -5
- package/lib/container/FallbackModule.js +4 -4
- package/lib/container/RemoteModule.js +4 -2
- package/lib/css/CssExportsGenerator.js +139 -0
- package/lib/css/CssGenerator.js +109 -0
- package/lib/css/CssLoadingRuntimeModule.js +440 -0
- package/lib/css/CssModulesPlugin.js +462 -0
- package/lib/css/CssParser.js +618 -0
- package/lib/css/walkCssTokens.js +659 -0
- package/lib/debug/ProfilingPlugin.js +24 -21
- package/lib/dependencies/AMDRequireDependency.js +6 -6
- package/lib/dependencies/CommonJsExportsParserPlugin.js +1 -2
- package/lib/dependencies/CommonJsFullRequireDependency.js +5 -1
- package/lib/dependencies/CommonJsImportsParserPlugin.js +5 -3
- package/lib/dependencies/CommonJsRequireContextDependency.js +5 -1
- package/lib/dependencies/ContextDependency.js +1 -0
- package/lib/dependencies/ContextDependencyHelpers.js +3 -3
- package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +4 -1
- package/lib/dependencies/ContextElementDependency.js +41 -3
- package/lib/dependencies/CreateScriptUrlDependency.js +12 -0
- package/lib/dependencies/CssExportDependency.js +85 -0
- package/lib/dependencies/CssImportDependency.js +75 -0
- package/lib/dependencies/CssLocalIdentifierDependency.js +119 -0
- package/lib/dependencies/CssSelfLocalIdentifierDependency.js +101 -0
- package/lib/dependencies/CssUrlDependency.js +132 -0
- package/lib/dependencies/ExportsInfoDependency.js +6 -0
- package/lib/dependencies/HarmonyAcceptImportDependency.js +5 -3
- package/lib/dependencies/HarmonyCompatibilityDependency.js +5 -5
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +95 -0
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +12 -3
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +25 -17
- package/lib/dependencies/HarmonyExportInitFragment.js +4 -1
- package/lib/dependencies/HarmonyImportDependency.js +23 -0
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +142 -45
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +46 -22
- package/lib/dependencies/HarmonyModulesPlugin.js +10 -0
- package/lib/dependencies/ImportContextDependency.js +0 -2
- package/lib/dependencies/ImportMetaContextDependency.js +35 -0
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +252 -0
- package/lib/dependencies/ImportMetaContextPlugin.js +59 -0
- package/lib/dependencies/ImportMetaPlugin.js +22 -3
- package/lib/dependencies/LoaderPlugin.js +4 -2
- package/lib/dependencies/RequireContextDependency.js +0 -16
- package/lib/dependencies/RequireEnsureDependency.js +2 -2
- package/lib/dependencies/URLDependency.js +3 -8
- package/lib/dependencies/URLPlugin.js +1 -1
- package/lib/esm/ModuleChunkFormatPlugin.js +74 -49
- package/lib/esm/ModuleChunkLoadingPlugin.js +3 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +25 -9
- package/lib/hmr/HotModuleReplacement.runtime.js +29 -14
- package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +4 -3
- package/lib/hmr/LazyCompilationPlugin.js +54 -26
- package/lib/hmr/lazyCompilationBackend.js +51 -12
- package/lib/ids/DeterministicModuleIdsPlugin.js +55 -35
- package/lib/ids/HashedModuleIdsPlugin.js +11 -14
- package/lib/ids/IdHelpers.js +25 -11
- package/lib/ids/NamedModuleIdsPlugin.js +6 -9
- package/lib/ids/NaturalModuleIdsPlugin.js +10 -13
- package/lib/ids/OccurrenceModuleIdsPlugin.js +13 -10
- package/lib/ids/SyncModuleIdsPlugin.js +140 -0
- package/lib/index.js +13 -0
- package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +2 -2
- package/lib/javascript/BasicEvaluatedExpression.js +5 -2
- package/lib/javascript/ChunkHelpers.js +33 -0
- package/lib/javascript/JavascriptGenerator.js +1 -0
- package/lib/javascript/JavascriptModulesPlugin.js +27 -2
- package/lib/javascript/JavascriptParser.js +82 -48
- package/lib/javascript/StartupHelpers.js +7 -30
- package/lib/library/AssignLibraryPlugin.js +39 -15
- package/lib/library/EnableLibraryPlugin.js +11 -0
- package/lib/library/UmdLibraryPlugin.js +5 -3
- package/lib/node/NodeTargetPlugin.js +3 -0
- package/lib/node/NodeWatchFileSystem.js +85 -31
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +23 -8
- package/lib/node/RequireChunkLoadingRuntimeModule.js +24 -9
- package/lib/optimize/ConcatenatedModule.js +21 -9
- package/lib/optimize/ModuleConcatenationPlugin.js +5 -2
- package/lib/optimize/SplitChunksPlugin.js +8 -1
- package/lib/runtime/AsyncModuleRuntimeModule.js +27 -17
- package/lib/runtime/BaseUriRuntimeModule.js +31 -0
- package/lib/runtime/CreateScriptRuntimeModule.js +36 -0
- package/lib/runtime/CreateScriptUrlRuntimeModule.js +9 -34
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +76 -0
- package/lib/schemes/HttpUriPlugin.js +77 -14
- package/lib/serialization/FileMiddleware.js +44 -9
- package/lib/sharing/ConsumeSharedModule.js +8 -2
- package/lib/sharing/ConsumeSharedRuntimeModule.js +26 -5
- package/lib/sharing/ProvideSharedModule.js +4 -2
- package/lib/sharing/ShareRuntimeModule.js +1 -1
- package/lib/sharing/utils.js +1 -1
- package/lib/stats/DefaultStatsFactoryPlugin.js +113 -68
- package/lib/stats/DefaultStatsPrinterPlugin.js +89 -24
- package/lib/util/ArrayHelpers.js +30 -0
- package/lib/util/AsyncQueue.js +1 -1
- package/lib/util/compileBooleanMatcher.js +1 -1
- package/lib/util/create-schema-validation.js +9 -2
- package/lib/util/createHash.js +12 -0
- package/lib/util/deprecation.js +10 -2
- package/lib/util/deterministicGrouping.js +1 -1
- package/lib/util/extractUrlAndGlobal.js +3 -0
- package/lib/util/fs.js +11 -0
- package/lib/util/hash/BatchedHash.js +7 -4
- package/lib/util/hash/md4.js +20 -0
- package/lib/util/hash/wasm-hash.js +163 -0
- package/lib/util/hash/xxhash64.js +5 -139
- package/lib/util/identifier.js +65 -44
- package/lib/util/internalSerializables.js +15 -0
- package/lib/util/nonNumericOnlyHash.js +22 -0
- package/lib/util/semver.js +17 -10
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +9 -3
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +20 -9
- package/lib/webpack.js +10 -3
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +3 -11
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +33 -22
- package/module.d.ts +215 -0
- package/package.json +23 -28
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +254 -29
- package/schemas/plugins/DllReferencePlugin.check.js +1 -1
- package/schemas/plugins/HashedModuleIdsPlugin.check.js +1 -1
- package/schemas/plugins/ProgressPlugin.check.js +1 -1
- package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -1
- package/schemas/plugins/asset/AssetParserOptions.check.js +1 -1
- package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +1 -1
- package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
- package/schemas/plugins/container/ContainerPlugin.json +2 -1
- package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
- package/schemas/plugins/container/ContainerReferencePlugin.json +1 -0
- package/schemas/plugins/container/ExternalsType.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.json +3 -1
- package/schemas/plugins/css/CssGeneratorOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssGeneratorOptions.check.js +6 -0
- package/schemas/plugins/css/CssGeneratorOptions.json +3 -0
- package/schemas/plugins/css/CssParserOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssParserOptions.check.js +6 -0
- package/schemas/plugins/css/CssParserOptions.json +3 -0
- package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.js +1 -1
- package/schemas/plugins/optimize/LimitChunkCountPlugin.check.js +1 -1
- package/schemas/plugins/optimize/MinChunkSizePlugin.check.js +1 -1
- package/schemas/plugins/schemes/HttpUriPlugin.check.js +1 -1
- package/schemas/plugins/schemes/HttpUriPlugin.json +4 -0
- package/types.d.ts +628 -179
@@ -123,9 +123,7 @@ class Profiler {
|
|
123
123
|
* @returns {Trace} The trace object
|
124
124
|
*/
|
125
125
|
const createTrace = (fs, outputPath) => {
|
126
|
-
const trace = new Tracer(
|
127
|
-
noStream: true
|
128
|
-
});
|
126
|
+
const trace = new Tracer();
|
129
127
|
const profiler = new Profiler(inspector);
|
130
128
|
if (/\/|\\/.test(outputPath)) {
|
131
129
|
const dirPath = dirname(fs, outputPath);
|
@@ -173,6 +171,7 @@ const createTrace = (fs, outputPath) => {
|
|
173
171
|
counter,
|
174
172
|
profiler,
|
175
173
|
end: callback => {
|
174
|
+
trace.push("]");
|
176
175
|
// Wait until the write stream finishes.
|
177
176
|
fsStream.on("close", () => {
|
178
177
|
callback();
|
@@ -203,15 +202,17 @@ class ProfilingPlugin {
|
|
203
202
|
|
204
203
|
// Compiler Hooks
|
205
204
|
Object.keys(compiler.hooks).forEach(hookName => {
|
206
|
-
compiler.hooks[hookName]
|
207
|
-
|
208
|
-
|
205
|
+
const hook = compiler.hooks[hookName];
|
206
|
+
if (hook) {
|
207
|
+
hook.intercept(makeInterceptorFor("Compiler", tracer)(hookName));
|
208
|
+
}
|
209
209
|
});
|
210
210
|
|
211
211
|
Object.keys(compiler.resolverFactory.hooks).forEach(hookName => {
|
212
|
-
compiler.resolverFactory.hooks[hookName]
|
213
|
-
|
214
|
-
|
212
|
+
const hook = compiler.resolverFactory.hooks[hookName];
|
213
|
+
if (hook) {
|
214
|
+
hook.intercept(makeInterceptorFor("Resolver", tracer)(hookName));
|
215
|
+
}
|
215
216
|
});
|
216
217
|
|
217
218
|
compiler.hooks.compilation.tap(
|
@@ -240,10 +241,10 @@ class ProfilingPlugin {
|
|
240
241
|
stage: Infinity
|
241
242
|
},
|
242
243
|
(stats, callback) => {
|
244
|
+
if (compiler.watchMode) return callback();
|
243
245
|
tracer.profiler.stopProfiling().then(parsedResults => {
|
244
246
|
if (parsedResults === undefined) {
|
245
247
|
tracer.profiler.destroy();
|
246
|
-
tracer.trace.flush();
|
247
248
|
tracer.end(callback);
|
248
249
|
return;
|
249
250
|
}
|
@@ -291,7 +292,6 @@ class ProfilingPlugin {
|
|
291
292
|
});
|
292
293
|
|
293
294
|
tracer.profiler.destroy();
|
294
|
-
tracer.trace.flush();
|
295
295
|
tracer.end(callback);
|
296
296
|
});
|
297
297
|
}
|
@@ -303,7 +303,7 @@ const interceptAllHooksFor = (instance, tracer, logLabel) => {
|
|
303
303
|
if (Reflect.has(instance, "hooks")) {
|
304
304
|
Object.keys(instance.hooks).forEach(hookName => {
|
305
305
|
const hook = instance.hooks[hookName];
|
306
|
-
if (!hook._fakeHook) {
|
306
|
+
if (hook && !hook._fakeHook) {
|
307
307
|
hook.intercept(makeInterceptorFor(logLabel, tracer)(hookName));
|
308
308
|
}
|
309
309
|
});
|
@@ -343,16 +343,19 @@ const interceptAllJavascriptModulesPluginHooks = (compilation, tracer) => {
|
|
343
343
|
};
|
344
344
|
|
345
345
|
const makeInterceptorFor = (instance, tracer) => hookName => ({
|
346
|
-
register:
|
347
|
-
const
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
346
|
+
register: tapInfo => {
|
347
|
+
const { name, type, fn } = tapInfo;
|
348
|
+
const newFn =
|
349
|
+
// Don't tap our own hooks to ensure stream can close cleanly
|
350
|
+
name === pluginName
|
351
|
+
? fn
|
352
|
+
: makeNewProfiledTapFn(hookName, tracer, {
|
353
|
+
name,
|
354
|
+
type,
|
355
|
+
fn
|
356
|
+
});
|
352
357
|
return {
|
353
|
-
|
354
|
-
type,
|
355
|
-
context,
|
358
|
+
...tapInfo,
|
356
359
|
fn: newFn
|
357
360
|
};
|
358
361
|
}
|
@@ -90,7 +90,7 @@ AMDRequireDependency.Template = class AMDRequireDependencyTemplate extends (
|
|
90
90
|
// has array range but no function range
|
91
91
|
if (dep.arrayRange && !dep.functionRange) {
|
92
92
|
const startBlock = `${promise}.then(function() {`;
|
93
|
-
const endBlock = `;})
|
93
|
+
const endBlock = `;})['catch'](${RuntimeGlobals.uncaughtErrorHandler})`;
|
94
94
|
runtimeRequirements.add(RuntimeGlobals.uncaughtErrorHandler);
|
95
95
|
|
96
96
|
source.replace(dep.outerRange[0], dep.arrayRange[0] - 1, startBlock);
|
@@ -103,7 +103,7 @@ AMDRequireDependency.Template = class AMDRequireDependencyTemplate extends (
|
|
103
103
|
// has function range but no array range
|
104
104
|
if (dep.functionRange && !dep.arrayRange) {
|
105
105
|
const startBlock = `${promise}.then((`;
|
106
|
-
const endBlock = `).bind(exports, __webpack_require__, exports, module))
|
106
|
+
const endBlock = `).bind(exports, __webpack_require__, exports, module))['catch'](${RuntimeGlobals.uncaughtErrorHandler})`;
|
107
107
|
runtimeRequirements.add(RuntimeGlobals.uncaughtErrorHandler);
|
108
108
|
|
109
109
|
source.replace(dep.outerRange[0], dep.functionRange[0] - 1, startBlock);
|
@@ -118,7 +118,7 @@ AMDRequireDependency.Template = class AMDRequireDependencyTemplate extends (
|
|
118
118
|
const startBlock = `${promise}.then(function() { `;
|
119
119
|
const errorRangeBlock = `}${
|
120
120
|
dep.functionBindThis ? ".bind(this)" : ""
|
121
|
-
})
|
121
|
+
})['catch'](`;
|
122
122
|
const endBlock = `${dep.errorCallbackBindThis ? ".bind(this)" : ""})`;
|
123
123
|
|
124
124
|
source.replace(dep.outerRange[0], dep.arrayRange[0] - 1, startBlock);
|
@@ -150,9 +150,9 @@ AMDRequireDependency.Template = class AMDRequireDependencyTemplate extends (
|
|
150
150
|
// has array range, function range, but no errorCallbackRange
|
151
151
|
if (dep.arrayRange && dep.functionRange) {
|
152
152
|
const startBlock = `${promise}.then(function() { `;
|
153
|
-
const endBlock = `}${
|
154
|
-
|
155
|
-
})`;
|
153
|
+
const endBlock = `}${
|
154
|
+
dep.functionBindThis ? ".bind(this)" : ""
|
155
|
+
})['catch'](${RuntimeGlobals.uncaughtErrorHandler})`;
|
156
156
|
runtimeRequirements.add(RuntimeGlobals.uncaughtErrorHandler);
|
157
157
|
|
158
158
|
source.replace(dep.outerRange[0], dep.arrayRange[0] - 1, startBlock);
|
@@ -201,7 +201,7 @@ class CommonJsExportsParserPlugin {
|
|
201
201
|
if (expr.arguments[1].type === "SpreadElement") return;
|
202
202
|
if (expr.arguments[2].type === "SpreadElement") return;
|
203
203
|
const exportsArg = parser.evaluateExpression(expr.arguments[0]);
|
204
|
-
if (!exportsArg
|
204
|
+
if (!exportsArg.isIdentifier()) return;
|
205
205
|
if (
|
206
206
|
exportsArg.identifier !== "exports" &&
|
207
207
|
exportsArg.identifier !== "module.exports" &&
|
@@ -210,7 +210,6 @@ class CommonJsExportsParserPlugin {
|
|
210
210
|
return;
|
211
211
|
}
|
212
212
|
const propertyArg = parser.evaluateExpression(expr.arguments[1]);
|
213
|
-
if (!propertyArg) return;
|
214
213
|
const property = propertyArg.asString();
|
215
214
|
if (typeof property !== "string") return;
|
216
215
|
enableStructuredExports();
|
@@ -117,7 +117,11 @@ CommonJsFullRequireDependency.Template = class CommonJsFullRequireDependencyTemp
|
|
117
117
|
const comment = equals(usedImported, ids)
|
118
118
|
? ""
|
119
119
|
: Template.toNormalComment(propertyAccess(ids)) + " ";
|
120
|
-
|
120
|
+
const access = `${comment}${propertyAccess(usedImported)}`;
|
121
|
+
requireExpr =
|
122
|
+
dep.asiSafe === true
|
123
|
+
? `(${requireExpr}${access})`
|
124
|
+
: `${requireExpr}${access}`;
|
121
125
|
}
|
122
126
|
}
|
123
127
|
source.replace(dep.range[0], dep.range[1] - 1, requireExpr);
|
@@ -141,7 +141,9 @@ class CommonJsImportsParserPlugin {
|
|
141
141
|
regExp: options.unknownContextRegExp,
|
142
142
|
mode: "sync"
|
143
143
|
},
|
144
|
-
expr.range
|
144
|
+
expr.range,
|
145
|
+
undefined,
|
146
|
+
parser.scope.inShorthand
|
145
147
|
);
|
146
148
|
dep.critical =
|
147
149
|
options.unknownContextCritical &&
|
@@ -280,7 +282,7 @@ class CommonJsImportsParserPlugin {
|
|
280
282
|
dep.asiSafe = !parser.isAsiPosition(expr.range[0]);
|
281
283
|
dep.optional = !!parser.scope.inTry;
|
282
284
|
dep.loc = expr.loc;
|
283
|
-
parser.state.
|
285
|
+
parser.state.current.addDependency(dep);
|
284
286
|
return true;
|
285
287
|
}
|
286
288
|
};
|
@@ -297,7 +299,7 @@ class CommonJsImportsParserPlugin {
|
|
297
299
|
dep.asiSafe = !parser.isAsiPosition(expr.range[0]);
|
298
300
|
dep.optional = !!parser.scope.inTry;
|
299
301
|
dep.loc = expr.callee.loc;
|
300
|
-
parser.state.
|
302
|
+
parser.state.current.addDependency(dep);
|
301
303
|
parser.walkExpressions(expr.arguments);
|
302
304
|
return true;
|
303
305
|
}
|
@@ -10,11 +10,13 @@ const ContextDependency = require("./ContextDependency");
|
|
10
10
|
const ContextDependencyTemplateAsRequireCall = require("./ContextDependencyTemplateAsRequireCall");
|
11
11
|
|
12
12
|
class CommonJsRequireContextDependency extends ContextDependency {
|
13
|
-
constructor(options, range, valueRange) {
|
13
|
+
constructor(options, range, valueRange, inShorthand) {
|
14
14
|
super(options);
|
15
15
|
|
16
16
|
this.range = range;
|
17
17
|
this.valueRange = valueRange;
|
18
|
+
// inShorthand must be serialized by subclasses that use it
|
19
|
+
this.inShorthand = inShorthand;
|
18
20
|
}
|
19
21
|
|
20
22
|
get type() {
|
@@ -26,6 +28,7 @@ class CommonJsRequireContextDependency extends ContextDependency {
|
|
26
28
|
|
27
29
|
write(this.range);
|
28
30
|
write(this.valueRange);
|
31
|
+
write(this.inShorthand);
|
29
32
|
|
30
33
|
super.serialize(context);
|
31
34
|
}
|
@@ -35,6 +38,7 @@ class CommonJsRequireContextDependency extends ContextDependency {
|
|
35
38
|
|
36
39
|
this.range = read();
|
37
40
|
this.valueRange = read();
|
41
|
+
this.inShorthand = read();
|
38
42
|
|
39
43
|
super.deserialize(context);
|
40
44
|
}
|
@@ -28,8 +28,8 @@ const splitContextFromPrefix = prefix => {
|
|
28
28
|
const idx = prefix.lastIndexOf("/");
|
29
29
|
let context = ".";
|
30
30
|
if (idx >= 0) {
|
31
|
-
context = prefix.
|
32
|
-
prefix = `.${prefix.
|
31
|
+
context = prefix.slice(0, idx);
|
32
|
+
prefix = `.${prefix.slice(idx)}`;
|
33
33
|
}
|
34
34
|
return {
|
35
35
|
context,
|
@@ -37,7 +37,7 @@ const splitContextFromPrefix = prefix => {
|
|
37
37
|
};
|
38
38
|
};
|
39
39
|
|
40
|
-
/** @typedef {Partial<Omit<ContextDependencyOptions, "resource"
|
40
|
+
/** @typedef {Partial<Omit<ContextDependencyOptions, "resource">>} PartialContextDependencyOptions */
|
41
41
|
|
42
42
|
/** @typedef {{ new(options: ContextDependencyOptions, range: [number, number], valueRange: [number, number]): ContextDependency }} ContextDependencyConstructor */
|
43
43
|
|
@@ -24,13 +24,16 @@ class ContextDependencyTemplateAsRequireCall extends ContextDependency.Template
|
|
24
24
|
{ runtimeTemplate, moduleGraph, chunkGraph, runtimeRequirements }
|
25
25
|
) {
|
26
26
|
const dep = /** @type {ContextDependency} */ (dependency);
|
27
|
-
|
27
|
+
let moduleExports = runtimeTemplate.moduleExports({
|
28
28
|
module: moduleGraph.getModule(dep),
|
29
29
|
chunkGraph,
|
30
30
|
request: dep.request,
|
31
31
|
runtimeRequirements
|
32
32
|
});
|
33
33
|
|
34
|
+
if (dep.inShorthand) {
|
35
|
+
moduleExports = `${dep.inShorthand}: ${moduleExports}`;
|
36
|
+
}
|
34
37
|
if (moduleGraph.getModule(dep)) {
|
35
38
|
if (dep.valueRange) {
|
36
39
|
if (Array.isArray(dep.replaces)) {
|
@@ -14,11 +14,27 @@ const ModuleDependency = require("./ModuleDependency");
|
|
14
14
|
/** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
|
15
15
|
|
16
16
|
class ContextElementDependency extends ModuleDependency {
|
17
|
-
|
17
|
+
/**
|
18
|
+
* @param {string} request request
|
19
|
+
* @param {string|undefined} userRequest user request
|
20
|
+
* @param {string} typePrefix type prefix
|
21
|
+
* @param {string} category category
|
22
|
+
* @param {string[][]=} referencedExports referenced exports
|
23
|
+
* @param {string=} context context
|
24
|
+
*/
|
25
|
+
constructor(
|
26
|
+
request,
|
27
|
+
userRequest,
|
28
|
+
typePrefix,
|
29
|
+
category,
|
30
|
+
referencedExports,
|
31
|
+
context
|
32
|
+
) {
|
18
33
|
super(request);
|
19
34
|
this.referencedExports = referencedExports;
|
20
35
|
this._typePrefix = typePrefix;
|
21
36
|
this._category = category;
|
37
|
+
this._context = context || undefined;
|
22
38
|
|
23
39
|
if (userRequest) {
|
24
40
|
this.userRequest = userRequest;
|
@@ -33,6 +49,20 @@ class ContextElementDependency extends ModuleDependency {
|
|
33
49
|
return "context element";
|
34
50
|
}
|
35
51
|
|
52
|
+
/**
|
53
|
+
* @returns {string | undefined} a request context
|
54
|
+
*/
|
55
|
+
getContext() {
|
56
|
+
return this._context;
|
57
|
+
}
|
58
|
+
|
59
|
+
/**
|
60
|
+
* @returns {string | null} an identifier to merge equal requests
|
61
|
+
*/
|
62
|
+
getResourceIdentifier() {
|
63
|
+
return `context${this._context || ""}|${super.getResourceIdentifier()}`;
|
64
|
+
}
|
65
|
+
|
36
66
|
get category() {
|
37
67
|
return this._category;
|
38
68
|
}
|
@@ -53,12 +83,20 @@ class ContextElementDependency extends ModuleDependency {
|
|
53
83
|
}
|
54
84
|
|
55
85
|
serialize(context) {
|
56
|
-
context
|
86
|
+
const { write } = context;
|
87
|
+
write(this._typePrefix);
|
88
|
+
write(this._category);
|
89
|
+
write(this._context);
|
90
|
+
write(this.referencedExports);
|
57
91
|
super.serialize(context);
|
58
92
|
}
|
59
93
|
|
60
94
|
deserialize(context) {
|
61
|
-
|
95
|
+
const { read } = context;
|
96
|
+
this._typePrefix = read();
|
97
|
+
this._category = read();
|
98
|
+
this._context = read();
|
99
|
+
this.referencedExports = read();
|
62
100
|
super.deserialize(context);
|
63
101
|
}
|
64
102
|
}
|
@@ -25,6 +25,18 @@ class CreateScriptUrlDependency extends NullDependency {
|
|
25
25
|
get type() {
|
26
26
|
return "create script url";
|
27
27
|
}
|
28
|
+
|
29
|
+
serialize(context) {
|
30
|
+
const { write } = context;
|
31
|
+
write(this.range);
|
32
|
+
super.serialize(context);
|
33
|
+
}
|
34
|
+
|
35
|
+
deserialize(context) {
|
36
|
+
const { read } = context;
|
37
|
+
this.range = read();
|
38
|
+
super.deserialize(context);
|
39
|
+
}
|
28
40
|
}
|
29
41
|
|
30
42
|
CreateScriptUrlDependency.Template = class CreateScriptUrlDependencyTemplate extends (
|
@@ -0,0 +1,85 @@
|
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Ivan Kopeykin @vankop
|
4
|
+
*/
|
5
|
+
|
6
|
+
"use strict";
|
7
|
+
|
8
|
+
const makeSerializable = require("../util/makeSerializable");
|
9
|
+
const NullDependency = require("./NullDependency");
|
10
|
+
|
11
|
+
/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
|
12
|
+
/** @typedef {import("../Dependency")} Dependency */
|
13
|
+
/** @typedef {import("../Dependency").ExportsSpec} ExportsSpec */
|
14
|
+
/** @typedef {import("../DependencyTemplate").CssDependencyTemplateContext} DependencyTemplateContext */
|
15
|
+
/** @typedef {import("../ModuleGraph")} ModuleGraph */
|
16
|
+
|
17
|
+
class CssExportDependency extends NullDependency {
|
18
|
+
/**
|
19
|
+
* @param {string} name name
|
20
|
+
* @param {string} value value
|
21
|
+
*/
|
22
|
+
constructor(name, value) {
|
23
|
+
super();
|
24
|
+
this.name = name;
|
25
|
+
this.value = value;
|
26
|
+
}
|
27
|
+
|
28
|
+
get type() {
|
29
|
+
return "css :export";
|
30
|
+
}
|
31
|
+
|
32
|
+
/**
|
33
|
+
* Returns the exported names
|
34
|
+
* @param {ModuleGraph} moduleGraph module graph
|
35
|
+
* @returns {ExportsSpec | undefined} export names
|
36
|
+
*/
|
37
|
+
getExports(moduleGraph) {
|
38
|
+
const name = this.name;
|
39
|
+
return {
|
40
|
+
exports: [
|
41
|
+
{
|
42
|
+
name,
|
43
|
+
canMangle: true
|
44
|
+
}
|
45
|
+
],
|
46
|
+
dependencies: undefined
|
47
|
+
};
|
48
|
+
}
|
49
|
+
|
50
|
+
serialize(context) {
|
51
|
+
const { write } = context;
|
52
|
+
write(this.name);
|
53
|
+
write(this.value);
|
54
|
+
super.serialize(context);
|
55
|
+
}
|
56
|
+
|
57
|
+
deserialize(context) {
|
58
|
+
const { read } = context;
|
59
|
+
this.name = read();
|
60
|
+
this.value = read();
|
61
|
+
super.deserialize(context);
|
62
|
+
}
|
63
|
+
}
|
64
|
+
|
65
|
+
CssExportDependency.Template = class CssExportDependencyTemplate extends (
|
66
|
+
NullDependency.Template
|
67
|
+
) {
|
68
|
+
/**
|
69
|
+
* @param {Dependency} dependency the dependency for which the template should be applied
|
70
|
+
* @param {ReplaceSource} source the current replace source which can be modified
|
71
|
+
* @param {DependencyTemplateContext} templateContext the context object
|
72
|
+
* @returns {void}
|
73
|
+
*/
|
74
|
+
apply(dependency, source, { cssExports }) {
|
75
|
+
const dep = /** @type {CssExportDependency} */ (dependency);
|
76
|
+
cssExports.set(dep.name, dep.value);
|
77
|
+
}
|
78
|
+
};
|
79
|
+
|
80
|
+
makeSerializable(
|
81
|
+
CssExportDependency,
|
82
|
+
"webpack/lib/dependencies/CssExportDependency"
|
83
|
+
);
|
84
|
+
|
85
|
+
module.exports = CssExportDependency;
|
@@ -0,0 +1,75 @@
|
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Ivan Kopeykin @vankop
|
4
|
+
*/
|
5
|
+
|
6
|
+
"use strict";
|
7
|
+
|
8
|
+
const makeSerializable = require("../util/makeSerializable");
|
9
|
+
const ModuleDependency = require("./ModuleDependency");
|
10
|
+
|
11
|
+
/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
|
12
|
+
/** @typedef {import("../ChunkGraph")} ChunkGraph */
|
13
|
+
/** @typedef {import("../Dependency")} Dependency */
|
14
|
+
/** @typedef {import("../Dependency").UpdateHashContext} UpdateHashContext */
|
15
|
+
/** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
|
16
|
+
/** @typedef {import("../Module")} Module */
|
17
|
+
/** @typedef {import("../ModuleGraph")} ModuleGraph */
|
18
|
+
/** @typedef {import("../ModuleGraphConnection")} ModuleGraphConnection */
|
19
|
+
/** @typedef {import("../ModuleGraphConnection").ConnectionState} ConnectionState */
|
20
|
+
/** @typedef {import("../util/Hash")} Hash */
|
21
|
+
/** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
|
22
|
+
|
23
|
+
class CssImportDependency extends ModuleDependency {
|
24
|
+
/**
|
25
|
+
* @param {string} request request
|
26
|
+
* @param {[number, number]} range range of the argument
|
27
|
+
* @param {string | undefined} supports list of supports conditions
|
28
|
+
* @param {string | undefined} media list of media conditions
|
29
|
+
*/
|
30
|
+
constructor(request, range, supports, media) {
|
31
|
+
super(request);
|
32
|
+
this.range = range;
|
33
|
+
this.supports = supports;
|
34
|
+
this.media = media;
|
35
|
+
}
|
36
|
+
|
37
|
+
get type() {
|
38
|
+
return "css @import";
|
39
|
+
}
|
40
|
+
|
41
|
+
get category() {
|
42
|
+
return "css-import";
|
43
|
+
}
|
44
|
+
|
45
|
+
/**
|
46
|
+
* @param {string} context context directory
|
47
|
+
* @returns {Module} a module
|
48
|
+
*/
|
49
|
+
createIgnoredModule(context) {
|
50
|
+
return null;
|
51
|
+
}
|
52
|
+
}
|
53
|
+
|
54
|
+
CssImportDependency.Template = class CssImportDependencyTemplate extends (
|
55
|
+
ModuleDependency.Template
|
56
|
+
) {
|
57
|
+
/**
|
58
|
+
* @param {Dependency} dependency the dependency for which the template should be applied
|
59
|
+
* @param {ReplaceSource} source the current replace source which can be modified
|
60
|
+
* @param {DependencyTemplateContext} templateContext the context object
|
61
|
+
* @returns {void}
|
62
|
+
*/
|
63
|
+
apply(dependency, source, templateContext) {
|
64
|
+
const dep = /** @type {CssImportDependency} */ (dependency);
|
65
|
+
|
66
|
+
source.replace(dep.range[0], dep.range[1] - 1, "");
|
67
|
+
}
|
68
|
+
};
|
69
|
+
|
70
|
+
makeSerializable(
|
71
|
+
CssImportDependency,
|
72
|
+
"webpack/lib/dependencies/CssImportDependency"
|
73
|
+
);
|
74
|
+
|
75
|
+
module.exports = CssImportDependency;
|
@@ -0,0 +1,119 @@
|
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Ivan Kopeykin @vankop
|
4
|
+
*/
|
5
|
+
|
6
|
+
"use strict";
|
7
|
+
|
8
|
+
const makeSerializable = require("../util/makeSerializable");
|
9
|
+
const NullDependency = require("./NullDependency");
|
10
|
+
|
11
|
+
/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
|
12
|
+
/** @typedef {import("../Dependency")} Dependency */
|
13
|
+
/** @typedef {import("../Dependency").ExportsSpec} ExportsSpec */
|
14
|
+
/** @typedef {import("../DependencyTemplate").CssDependencyTemplateContext} DependencyTemplateContext */
|
15
|
+
/** @typedef {import("../ModuleGraph")} ModuleGraph */
|
16
|
+
|
17
|
+
class CssLocalIdentifierDependency extends NullDependency {
|
18
|
+
/**
|
19
|
+
* @param {string} name name
|
20
|
+
* @param {[number, number]} range range
|
21
|
+
* @param {string=} prefix prefix
|
22
|
+
*/
|
23
|
+
constructor(name, range, prefix = "") {
|
24
|
+
super();
|
25
|
+
this.name = name;
|
26
|
+
this.range = range;
|
27
|
+
this.prefix = prefix;
|
28
|
+
}
|
29
|
+
|
30
|
+
get type() {
|
31
|
+
return "css local identifier";
|
32
|
+
}
|
33
|
+
|
34
|
+
/**
|
35
|
+
* Returns the exported names
|
36
|
+
* @param {ModuleGraph} moduleGraph module graph
|
37
|
+
* @returns {ExportsSpec | undefined} export names
|
38
|
+
*/
|
39
|
+
getExports(moduleGraph) {
|
40
|
+
const name = this.name;
|
41
|
+
return {
|
42
|
+
exports: [
|
43
|
+
{
|
44
|
+
name,
|
45
|
+
canMangle: true
|
46
|
+
}
|
47
|
+
],
|
48
|
+
dependencies: undefined
|
49
|
+
};
|
50
|
+
}
|
51
|
+
|
52
|
+
serialize(context) {
|
53
|
+
const { write } = context;
|
54
|
+
write(this.name);
|
55
|
+
write(this.range);
|
56
|
+
write(this.prefix);
|
57
|
+
super.serialize(context);
|
58
|
+
}
|
59
|
+
|
60
|
+
deserialize(context) {
|
61
|
+
const { read } = context;
|
62
|
+
this.name = read();
|
63
|
+
this.range = read();
|
64
|
+
this.prefix = read();
|
65
|
+
super.deserialize(context);
|
66
|
+
}
|
67
|
+
}
|
68
|
+
|
69
|
+
const escapeCssIdentifier = (str, omitUnderscore) => {
|
70
|
+
const escaped = `${str}`.replace(
|
71
|
+
// cspell:word uffff
|
72
|
+
/[^a-zA-Z0-9_\u0081-\uffff-]/g,
|
73
|
+
s => `\\${s}`
|
74
|
+
);
|
75
|
+
return !omitUnderscore && /^(?!--)[0-9-]/.test(escaped)
|
76
|
+
? `_${escaped}`
|
77
|
+
: escaped;
|
78
|
+
};
|
79
|
+
|
80
|
+
CssLocalIdentifierDependency.Template = class CssLocalIdentifierDependencyTemplate extends (
|
81
|
+
NullDependency.Template
|
82
|
+
) {
|
83
|
+
/**
|
84
|
+
* @param {Dependency} dependency the dependency for which the template should be applied
|
85
|
+
* @param {ReplaceSource} source the current replace source which can be modified
|
86
|
+
* @param {DependencyTemplateContext} templateContext the context object
|
87
|
+
* @returns {void}
|
88
|
+
*/
|
89
|
+
apply(
|
90
|
+
dependency,
|
91
|
+
source,
|
92
|
+
{ module, moduleGraph, chunkGraph, runtime, runtimeTemplate, cssExports }
|
93
|
+
) {
|
94
|
+
const dep = /** @type {CssLocalIdentifierDependency} */ (dependency);
|
95
|
+
const used = moduleGraph
|
96
|
+
.getExportInfo(module, dep.name)
|
97
|
+
.getUsedName(dep.name, runtime);
|
98
|
+
const moduleId = chunkGraph.getModuleId(module);
|
99
|
+
const identifier =
|
100
|
+
dep.prefix +
|
101
|
+
(runtimeTemplate.outputOptions.uniqueName
|
102
|
+
? runtimeTemplate.outputOptions.uniqueName + "-"
|
103
|
+
: "") +
|
104
|
+
(used ? moduleId + "-" + used : "-");
|
105
|
+
source.replace(
|
106
|
+
dep.range[0],
|
107
|
+
dep.range[1] - 1,
|
108
|
+
escapeCssIdentifier(identifier, dep.prefix)
|
109
|
+
);
|
110
|
+
if (used) cssExports.set(used, identifier);
|
111
|
+
}
|
112
|
+
};
|
113
|
+
|
114
|
+
makeSerializable(
|
115
|
+
CssLocalIdentifierDependency,
|
116
|
+
"webpack/lib/dependencies/CssLocalIdentifierDependency"
|
117
|
+
);
|
118
|
+
|
119
|
+
module.exports = CssLocalIdentifierDependency;
|