webpack 5.99.6 → 5.99.8
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/lib/AutomaticPrefetchPlugin.js +21 -22
- package/lib/BannerPlugin.js +31 -35
- package/lib/CleanPlugin.js +5 -3
- package/lib/Compilation.js +21 -15
- package/lib/Compiler.js +2 -1
- package/lib/ContextExclusionPlugin.js +4 -2
- package/lib/ContextModule.js +1 -1
- package/lib/ContextModuleFactory.js +1 -2
- package/lib/ContextReplacementPlugin.js +7 -4
- package/lib/DefinePlugin.js +2 -2
- package/lib/DelegatedModule.js +18 -8
- package/lib/DelegatedModuleFactoryPlugin.js +9 -7
- package/lib/DelegatedPlugin.js +4 -2
- package/lib/DllEntryPlugin.js +4 -2
- package/lib/DllPlugin.js +5 -3
- package/lib/DllReferencePlugin.js +56 -60
- package/lib/DynamicEntryPlugin.js +4 -2
- package/lib/EntryOptionPlugin.js +3 -1
- package/lib/EntryPlugin.js +4 -2
- package/lib/EnvironmentPlugin.js +4 -2
- package/lib/EvalDevToolModulePlugin.js +9 -7
- package/lib/EvalSourceMapDevToolPlugin.js +138 -139
- package/lib/ExportsInfo.js +35 -16
- package/lib/ExternalModule.js +6 -5
- package/lib/ExternalsPlugin.js +3 -1
- package/lib/FileSystemInfo.js +2 -2
- package/lib/FlagDependencyExportsPlugin.js +2 -1
- package/lib/IgnorePlugin.js +6 -4
- package/lib/IgnoreWarningsPlugin.js +4 -2
- package/lib/LibManifestPlugin.js +5 -6
- package/lib/LoaderOptionsPlugin.js +4 -2
- package/lib/LoaderTargetPlugin.js +4 -2
- package/lib/Module.js +19 -12
- package/lib/ModuleFilenameHelpers.js +8 -4
- package/lib/ModuleInfoHeaderPlugin.js +11 -12
- package/lib/MultiCompiler.js +5 -3
- package/lib/NoEmitOnErrorsPlugin.js +5 -3
- package/lib/NormalModule.js +13 -8
- package/lib/NormalModuleReplacementPlugin.js +33 -36
- package/lib/PlatformPlugin.js +3 -1
- package/lib/PrefetchPlugin.js +4 -2
- package/lib/ProgressPlugin.js +23 -26
- package/lib/RecordIdsPlugin.js +72 -102
- package/lib/RuntimePlugin.js +34 -32
- package/lib/SourceMapDevToolPlugin.js +9 -8
- package/lib/WarnCaseSensitiveModulesPlugin.js +36 -37
- package/lib/WarnNoModeSetPlugin.js +3 -1
- package/lib/WatchIgnorePlugin.js +3 -1
- package/lib/WebpackError.js +11 -3
- package/lib/WebpackOptionsApply.js +6 -7
- package/lib/asset/AssetGenerator.js +2 -2
- package/lib/async-modules/InferAsyncModulesPlugin.js +25 -26
- package/lib/cache/IdleFileCachePlugin.js +11 -12
- package/lib/cache/MemoryWithGcCachePlugin.js +7 -5
- package/lib/cache/ResolverCachePlugin.js +8 -6
- package/lib/cli.js +5 -1
- package/lib/config/defaults.js +10 -6
- package/lib/config/normalization.js +14 -8
- package/lib/container/ContainerReferencePlugin.js +24 -26
- package/lib/container/ModuleFederationPlugin.js +2 -1
- package/lib/css/CssGenerator.js +1 -1
- package/lib/css/CssModulesPlugin.js +8 -6
- package/lib/debug/ProfilingPlugin.js +18 -21
- package/lib/dependencies/CommonJsImportsParserPlugin.js +1 -1
- package/lib/dependencies/ContextElementDependency.js +1 -1
- package/lib/dependencies/CssLocalIdentifierDependency.js +2 -2
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +9 -15
- package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +15 -15
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +4 -2
- package/lib/dependencies/LoaderPlugin.js +5 -3
- package/lib/dependencies/RequireContextDependencyParserPlugin.js +46 -46
- package/lib/dependencies/RequireContextPlugin.js +2 -1
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +94 -100
- package/lib/dependencies/WorkerPlugin.js +2 -2
- package/lib/esm/ModuleChunkLoadingPlugin.js +72 -73
- package/lib/hmr/HotModuleReplacement.runtime.js +0 -1
- package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +0 -2
- package/lib/hmr/LazyCompilationPlugin.js +17 -18
- package/lib/ids/ChunkModuleIdRangePlugin.js +6 -6
- package/lib/ids/DeterministicModuleIdsPlugin.js +47 -48
- package/lib/ids/HashedModuleIdsPlugin.js +4 -2
- package/lib/ids/NamedChunkIdsPlugin.js +4 -2
- package/lib/ids/NamedModuleIdsPlugin.js +4 -2
- package/lib/ids/NaturalChunkIdsPlugin.js +4 -2
- package/lib/ids/NaturalModuleIdsPlugin.js +4 -2
- package/lib/ids/OccurrenceChunkIdsPlugin.js +4 -2
- package/lib/ids/OccurrenceModuleIdsPlugin.js +4 -2
- package/lib/index.js +11 -0
- package/lib/javascript/JavascriptModulesPlugin.js +2 -2
- package/lib/javascript/JavascriptParser.js +634 -656
- package/lib/json/JsonModulesPlugin.js +4 -4
- package/lib/library/AbstractLibraryPlugin.js +1 -1
- package/lib/library/ModuleLibraryPlugin.js +60 -42
- package/lib/node/CommonJsChunkLoadingPlugin.js +69 -73
- package/lib/node/NodeEnvironmentPlugin.js +3 -1
- package/lib/node/nodeConsole.js +3 -2
- package/lib/optimize/AggressiveSplittingPlugin.js +224 -232
- package/lib/optimize/ConcatenatedModule.js +15 -16
- package/lib/optimize/FlagIncludedChunksPlugin.js +92 -97
- package/lib/optimize/LimitChunkCountPlugin.js +4 -2
- package/lib/optimize/MangleExportsPlugin.js +15 -16
- package/lib/optimize/MinChunkSizePlugin.js +4 -2
- package/lib/optimize/ModuleConcatenationPlugin.js +6 -4
- package/lib/optimize/RealContentHashPlugin.js +4 -2
- package/lib/optimize/RemoveEmptyChunksPlugin.js +5 -3
- package/lib/optimize/RemoveParentModulesPlugin.js +4 -2
- package/lib/optimize/RuntimeChunkPlugin.js +21 -23
- package/lib/optimize/SideEffectsFlagPlugin.js +9 -6
- package/lib/optimize/SplitChunksPlugin.js +9 -7
- package/lib/performance/SizeLimitsPlugin.js +3 -1
- package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +61 -62
- package/lib/rules/BasicEffectRulePlugin.js +1 -2
- package/lib/rules/ObjectMatcherRulePlugin.js +2 -1
- package/lib/rules/RuleSetCompiler.js +19 -5
- package/lib/rules/UseEffectRulePlugin.js +4 -6
- package/lib/runtime/StartupChunkDependenciesPlugin.js +39 -42
- package/lib/schemes/DataUriPlugin.js +5 -3
- package/lib/schemes/FileUriPlugin.js +5 -3
- package/lib/schemes/HttpUriPlugin.js +186 -188
- package/lib/serialization/AggregateErrorSerializer.js +42 -0
- package/lib/serialization/ErrorObjectSerializer.js +7 -2
- package/lib/serialization/ObjectMiddleware.js +13 -0
- package/lib/sharing/ProvideSharedPlugin.js +6 -4
- package/lib/stats/DefaultStatsFactoryPlugin.js +89 -33
- package/lib/stats/DefaultStatsPresetPlugin.js +25 -20
- package/lib/stats/DefaultStatsPrinterPlugin.js +306 -341
- package/lib/util/concatenate.js +4 -2
- package/lib/util/createHash.js +3 -3
- package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +55 -57
- package/lib/web/JsonpChunkLoadingPlugin.js +73 -74
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +77 -78
- package/package.json +35 -30
- package/schemas/WebpackOptions.check.d.ts +1 -1
- package/schemas/WebpackOptions.check.js +2 -2
- package/schemas/WebpackOptions.json +267 -26
- package/schemas/plugins/BannerPlugin.check.d.ts +1 -1
- package/schemas/plugins/BannerPlugin.check.js +1 -1
- package/schemas/plugins/DllPlugin.check.d.ts +1 -1
- package/schemas/plugins/DllPlugin.check.js +1 -1
- package/schemas/plugins/DllReferencePlugin.check.d.ts +1 -1
- package/schemas/plugins/DllReferencePlugin.check.js +1 -1
- package/schemas/plugins/HashedModuleIdsPlugin.check.d.ts +1 -1
- package/schemas/plugins/HashedModuleIdsPlugin.check.js +1 -1
- package/schemas/plugins/IgnorePlugin.check.d.ts +1 -1
- package/schemas/plugins/IgnorePlugin.check.js +1 -1
- package/schemas/plugins/LoaderOptionsPlugin.check.d.ts +1 -1
- package/schemas/plugins/LoaderOptionsPlugin.check.js +1 -1
- package/schemas/plugins/ProgressPlugin.check.d.ts +1 -1
- package/schemas/plugins/ProgressPlugin.check.js +1 -1
- package/schemas/plugins/SourceMapDevToolPlugin.check.d.ts +1 -1
- package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
- package/schemas/plugins/SourceMapDevToolPlugin.json +2 -2
- package/schemas/plugins/WatchIgnorePlugin.check.d.ts +1 -1
- package/schemas/plugins/WatchIgnorePlugin.check.js +1 -1
- package/schemas/plugins/asset/AssetGeneratorOptions.check.d.ts +1 -1
- package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -1
- package/schemas/plugins/asset/AssetInlineGeneratorOptions.check.d.ts +1 -1
- package/schemas/plugins/asset/AssetInlineGeneratorOptions.check.js +1 -1
- package/schemas/plugins/asset/AssetParserOptions.check.d.ts +1 -1
- package/schemas/plugins/asset/AssetParserOptions.check.js +1 -1
- package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.d.ts +1 -1
- package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +1 -1
- package/schemas/plugins/container/ContainerPlugin.check.d.ts +1 -1
- package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
- package/schemas/plugins/container/ContainerReferencePlugin.check.d.ts +1 -1
- package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
- package/schemas/plugins/container/ExternalsType.check.d.ts +1 -1
- package/schemas/plugins/container/ExternalsType.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.check.d.ts +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
- package/schemas/plugins/css/CssAutoGeneratorOptions.check.d.ts +1 -1
- package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssAutoParserOptions.check.d.ts +1 -1
- package/schemas/plugins/css/CssAutoParserOptions.check.js +1 -1
- package/schemas/plugins/css/CssGeneratorOptions.check.d.ts +1 -1
- package/schemas/plugins/css/CssGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssGlobalGeneratorOptions.check.d.ts +1 -1
- package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssGlobalParserOptions.check.d.ts +1 -1
- package/schemas/plugins/css/CssGlobalParserOptions.check.js +1 -1
- package/schemas/plugins/css/CssModuleGeneratorOptions.check.d.ts +1 -1
- package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssModuleParserOptions.check.d.ts +1 -1
- package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
- package/schemas/plugins/css/CssParserOptions.check.d.ts +1 -1
- package/schemas/plugins/css/CssParserOptions.check.js +1 -1
- package/schemas/plugins/debug/ProfilingPlugin.check.d.ts +1 -1
- package/schemas/plugins/debug/ProfilingPlugin.check.js +1 -1
- package/schemas/plugins/ids/OccurrenceChunkIdsPlugin.check.d.ts +1 -1
- package/schemas/plugins/ids/OccurrenceChunkIdsPlugin.check.js +1 -1
- package/schemas/plugins/ids/OccurrenceModuleIdsPlugin.check.d.ts +1 -1
- package/schemas/plugins/ids/OccurrenceModuleIdsPlugin.check.js +1 -1
- package/schemas/plugins/json/JsonModulesPluginGenerator.check.d.ts +7 -0
- package/schemas/plugins/{JsonModulesPluginGenerator.check.js → json/JsonModulesPluginGenerator.check.js} +1 -1
- package/schemas/plugins/json/JsonModulesPluginGenerator.json +3 -0
- package/schemas/plugins/json/JsonModulesPluginParser.check.d.ts +7 -0
- package/schemas/plugins/{JsonModulesPluginParser.check.js → json/JsonModulesPluginParser.check.js} +1 -1
- package/schemas/plugins/json/JsonModulesPluginParser.json +3 -0
- package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.d.ts +1 -1
- package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.js +1 -1
- package/schemas/plugins/optimize/LimitChunkCountPlugin.check.d.ts +1 -1
- package/schemas/plugins/optimize/LimitChunkCountPlugin.check.js +1 -1
- package/schemas/plugins/optimize/MergeDuplicateChunksPlugin.check.d.ts +1 -1
- package/schemas/plugins/optimize/MergeDuplicateChunksPlugin.check.js +1 -1
- package/schemas/plugins/optimize/MinChunkSizePlugin.check.d.ts +1 -1
- package/schemas/plugins/optimize/MinChunkSizePlugin.check.js +1 -1
- package/schemas/plugins/schemes/HttpUriPlugin.check.d.ts +1 -1
- package/schemas/plugins/schemes/HttpUriPlugin.check.js +1 -1
- package/schemas/plugins/sharing/ConsumeSharedPlugin.check.d.ts +1 -1
- package/schemas/plugins/sharing/ConsumeSharedPlugin.check.js +1 -1
- package/schemas/plugins/sharing/ProvideSharedPlugin.check.d.ts +1 -1
- package/schemas/plugins/sharing/ProvideSharedPlugin.check.js +1 -1
- package/schemas/plugins/sharing/SharePlugin.check.d.ts +1 -1
- package/schemas/plugins/sharing/SharePlugin.check.js +1 -1
- package/types.d.ts +587 -207
- package/schemas/plugins/JsonModulesPluginGenerator.check.d.ts +0 -7
- package/schemas/plugins/JsonModulesPluginGenerator.json +0 -11
- package/schemas/plugins/JsonModulesPluginParser.check.d.ts +0 -7
- package/schemas/plugins/JsonModulesPluginParser.json +0 -16
@@ -32,6 +32,8 @@ const validate = createSchemaValidation(
|
|
32
32
|
|
33
33
|
/** @typedef {{ path: string, data: DllReferencePluginOptionsManifest | undefined, error: Error | undefined }} CompilationDataItem */
|
34
34
|
|
35
|
+
const PLUGIN_NAME = "DllReferencePlugin";
|
36
|
+
|
35
37
|
class DllReferencePlugin {
|
36
38
|
/**
|
37
39
|
* @param {DllReferencePluginOptions} options options object
|
@@ -50,7 +52,7 @@ class DllReferencePlugin {
|
|
50
52
|
*/
|
51
53
|
apply(compiler) {
|
52
54
|
compiler.hooks.compilation.tap(
|
53
|
-
|
55
|
+
PLUGIN_NAME,
|
54
56
|
(compilation, { normalModuleFactory }) => {
|
55
57
|
compilation.dependencyFactories.set(
|
56
58
|
DelegatedSourceDependency,
|
@@ -59,51 +61,48 @@ class DllReferencePlugin {
|
|
59
61
|
}
|
60
62
|
);
|
61
63
|
|
62
|
-
compiler.hooks.beforeCompile.tapAsync(
|
63
|
-
"
|
64
|
-
|
65
|
-
if (
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
});
|
99
|
-
return;
|
100
|
-
}
|
64
|
+
compiler.hooks.beforeCompile.tapAsync(PLUGIN_NAME, (params, callback) => {
|
65
|
+
if ("manifest" in this.options) {
|
66
|
+
const manifest = this.options.manifest;
|
67
|
+
if (typeof manifest === "string") {
|
68
|
+
/** @type {InputFileSystem} */
|
69
|
+
(compiler.inputFileSystem).readFile(manifest, (err, result) => {
|
70
|
+
if (err) return callback(err);
|
71
|
+
/** @type {CompilationDataItem} */
|
72
|
+
const data = {
|
73
|
+
path: manifest,
|
74
|
+
data: undefined,
|
75
|
+
error: undefined
|
76
|
+
};
|
77
|
+
// Catch errors parsing the manifest so that blank
|
78
|
+
// or malformed manifest files don't kill the process.
|
79
|
+
try {
|
80
|
+
data.data = parseJson(
|
81
|
+
/** @type {Buffer} */ (result).toString("utf-8")
|
82
|
+
);
|
83
|
+
} catch (parseErr) {
|
84
|
+
// Store the error in the params so that it can
|
85
|
+
// be added as a compilation error later on.
|
86
|
+
const manifestPath = makePathsRelative(
|
87
|
+
/** @type {string} */ (compiler.options.context),
|
88
|
+
manifest,
|
89
|
+
compiler.root
|
90
|
+
);
|
91
|
+
data.error = new DllManifestError(
|
92
|
+
manifestPath,
|
93
|
+
/** @type {Error} */ (parseErr).message
|
94
|
+
);
|
95
|
+
}
|
96
|
+
this._compilationData.set(params, data);
|
97
|
+
return callback();
|
98
|
+
});
|
99
|
+
return;
|
101
100
|
}
|
102
|
-
return callback();
|
103
101
|
}
|
104
|
-
|
102
|
+
return callback();
|
103
|
+
});
|
105
104
|
|
106
|
-
compiler.hooks.compile.tap(
|
105
|
+
compiler.hooks.compile.tap(PLUGIN_NAME, params => {
|
107
106
|
let name = this.options.name;
|
108
107
|
let sourceType = this.options.sourceType;
|
109
108
|
let resolvedContent =
|
@@ -154,27 +153,24 @@ class DllReferencePlugin {
|
|
154
153
|
}).apply(normalModuleFactory);
|
155
154
|
});
|
156
155
|
|
157
|
-
compiler.hooks.compilation.tap(
|
158
|
-
"
|
159
|
-
|
160
|
-
if (
|
161
|
-
const
|
162
|
-
|
163
|
-
|
164
|
-
|
156
|
+
compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation, params) => {
|
157
|
+
if ("manifest" in this.options) {
|
158
|
+
const manifest = this.options.manifest;
|
159
|
+
if (typeof manifest === "string") {
|
160
|
+
const data = /** @type {CompilationDataItem} */ (
|
161
|
+
this._compilationData.get(params)
|
162
|
+
);
|
163
|
+
// If there was an error parsing the manifest file, add the
|
164
|
+
// error as a compilation error to make the compilation fail.
|
165
|
+
if (data.error) {
|
166
|
+
compilation.errors.push(
|
167
|
+
/** @type {DllManifestError} */ (data.error)
|
165
168
|
);
|
166
|
-
// If there was an error parsing the manifest file, add the
|
167
|
-
// error as a compilation error to make the compilation fail.
|
168
|
-
if (data.error) {
|
169
|
-
compilation.errors.push(
|
170
|
-
/** @type {DllManifestError} */ (data.error)
|
171
|
-
);
|
172
|
-
}
|
173
|
-
compilation.fileDependencies.add(manifest);
|
174
169
|
}
|
170
|
+
compilation.fileDependencies.add(manifest);
|
175
171
|
}
|
176
172
|
}
|
177
|
-
);
|
173
|
+
});
|
178
174
|
}
|
179
175
|
}
|
180
176
|
|
@@ -15,6 +15,8 @@ const EntryDependency = require("./dependencies/EntryDependency");
|
|
15
15
|
/** @typedef {import("../declarations/WebpackOptions").EntryStaticNormalized} EntryStatic */
|
16
16
|
/** @typedef {import("./Compiler")} Compiler */
|
17
17
|
|
18
|
+
const PLUGIN_NAME = "DynamicEntryPlugin";
|
19
|
+
|
18
20
|
class DynamicEntryPlugin {
|
19
21
|
/**
|
20
22
|
* @param {string} context the context path
|
@@ -32,7 +34,7 @@ class DynamicEntryPlugin {
|
|
32
34
|
*/
|
33
35
|
apply(compiler) {
|
34
36
|
compiler.hooks.compilation.tap(
|
35
|
-
|
37
|
+
PLUGIN_NAME,
|
36
38
|
(compilation, { normalModuleFactory }) => {
|
37
39
|
compilation.dependencyFactories.set(
|
38
40
|
EntryDependency,
|
@@ -41,7 +43,7 @@ class DynamicEntryPlugin {
|
|
41
43
|
}
|
42
44
|
);
|
43
45
|
|
44
|
-
compiler.hooks.make.tapPromise(
|
46
|
+
compiler.hooks.make.tapPromise(PLUGIN_NAME, compilation =>
|
45
47
|
Promise.resolve(this.entry())
|
46
48
|
.then(entry => {
|
47
49
|
const promises = [];
|
package/lib/EntryOptionPlugin.js
CHANGED
@@ -10,13 +10,15 @@
|
|
10
10
|
/** @typedef {import("./Compiler")} Compiler */
|
11
11
|
/** @typedef {import("./Entrypoint").EntryOptions} EntryOptions */
|
12
12
|
|
13
|
+
const PLUGIN_NAME = "EntryOptionPlugin";
|
14
|
+
|
13
15
|
class EntryOptionPlugin {
|
14
16
|
/**
|
15
17
|
* @param {Compiler} compiler the compiler instance one is tapping into
|
16
18
|
* @returns {void}
|
17
19
|
*/
|
18
20
|
apply(compiler) {
|
19
|
-
compiler.hooks.entryOption.tap(
|
21
|
+
compiler.hooks.entryOption.tap(PLUGIN_NAME, (context, entry) => {
|
20
22
|
EntryOptionPlugin.applyEntryOption(compiler, context, entry);
|
21
23
|
return true;
|
22
24
|
});
|
package/lib/EntryPlugin.js
CHANGED
@@ -10,6 +10,8 @@ const EntryDependency = require("./dependencies/EntryDependency");
|
|
10
10
|
/** @typedef {import("./Compiler")} Compiler */
|
11
11
|
/** @typedef {import("./Entrypoint").EntryOptions} EntryOptions */
|
12
12
|
|
13
|
+
const PLUGIN_NAME = "EntryPlugin";
|
14
|
+
|
13
15
|
class EntryPlugin {
|
14
16
|
/**
|
15
17
|
* An entry plugin which will handle creation of the EntryDependency
|
@@ -30,7 +32,7 @@ class EntryPlugin {
|
|
30
32
|
*/
|
31
33
|
apply(compiler) {
|
32
34
|
compiler.hooks.compilation.tap(
|
33
|
-
|
35
|
+
PLUGIN_NAME,
|
34
36
|
(compilation, { normalModuleFactory }) => {
|
35
37
|
compilation.dependencyFactories.set(
|
36
38
|
EntryDependency,
|
@@ -42,7 +44,7 @@ class EntryPlugin {
|
|
42
44
|
const { entry, options, context } = this;
|
43
45
|
const dep = EntryPlugin.createDependency(entry, options);
|
44
46
|
|
45
|
-
compiler.hooks.make.tapAsync(
|
47
|
+
compiler.hooks.make.tapAsync(PLUGIN_NAME, (compilation, callback) => {
|
46
48
|
compilation.addEntry(context, dep, options, err => {
|
47
49
|
callback(err);
|
48
50
|
});
|
package/lib/EnvironmentPlugin.js
CHANGED
@@ -11,6 +11,8 @@ const WebpackError = require("./WebpackError");
|
|
11
11
|
/** @typedef {import("./Compiler")} Compiler */
|
12
12
|
/** @typedef {import("./DefinePlugin").CodeValue} CodeValue */
|
13
13
|
|
14
|
+
const PLUGIN_NAME = "EnvironmentPlugin";
|
15
|
+
|
14
16
|
class EnvironmentPlugin {
|
15
17
|
/**
|
16
18
|
* @param {(string | string[] | Record<string, EXPECTED_ANY>)[]} keys keys
|
@@ -46,9 +48,9 @@ class EnvironmentPlugin {
|
|
46
48
|
: this.defaultValues[key];
|
47
49
|
|
48
50
|
if (value === undefined) {
|
49
|
-
compiler.hooks.thisCompilation.tap(
|
51
|
+
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, compilation => {
|
50
52
|
const error = new WebpackError(
|
51
|
-
|
53
|
+
`${PLUGIN_NAME} - ${key} environment variable is undefined.\n\n` +
|
52
54
|
"You can pass an object with default values to suppress this warning.\n" +
|
53
55
|
"See https://webpack.js.org/plugins/environment-plugin for example."
|
54
56
|
);
|
@@ -35,6 +35,8 @@ const devtoolWarning = new RawSource(`/*
|
|
35
35
|
* @property {OutputOptions["devtoolModuleFilenameTemplate"]=} moduleFilenameTemplate module filename template
|
36
36
|
*/
|
37
37
|
|
38
|
+
const PLUGIN_NAME = "EvalDevToolModulePlugin";
|
39
|
+
|
38
40
|
class EvalDevToolModulePlugin {
|
39
41
|
/**
|
40
42
|
* @param {EvalDevToolModulePluginOptions=} options options
|
@@ -53,10 +55,10 @@ class EvalDevToolModulePlugin {
|
|
53
55
|
* @returns {void}
|
54
56
|
*/
|
55
57
|
apply(compiler) {
|
56
|
-
compiler.hooks.compilation.tap(
|
58
|
+
compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => {
|
57
59
|
const hooks = JavascriptModulesPlugin.getCompilationHooks(compilation);
|
58
60
|
hooks.renderModuleContent.tap(
|
59
|
-
|
61
|
+
PLUGIN_NAME,
|
60
62
|
(source, module, { chunk, runtimeTemplate, chunkGraph }) => {
|
61
63
|
const cacheEntry = cache.get(source);
|
62
64
|
if (cacheEntry !== undefined) return cacheEntry;
|
@@ -103,20 +105,20 @@ class EvalDevToolModulePlugin {
|
|
103
105
|
}
|
104
106
|
);
|
105
107
|
hooks.inlineInRuntimeBailout.tap(
|
106
|
-
|
108
|
+
PLUGIN_NAME,
|
107
109
|
() => "the eval devtool is used."
|
108
110
|
);
|
109
111
|
hooks.render.tap(
|
110
|
-
|
112
|
+
PLUGIN_NAME,
|
111
113
|
source => new ConcatSource(devtoolWarning, source)
|
112
114
|
);
|
113
|
-
hooks.chunkHash.tap(
|
114
|
-
hash.update(
|
115
|
+
hooks.chunkHash.tap(PLUGIN_NAME, (chunk, hash) => {
|
116
|
+
hash.update(PLUGIN_NAME);
|
115
117
|
hash.update("2");
|
116
118
|
});
|
117
119
|
if (compilation.outputOptions.trustedTypes) {
|
118
120
|
compilation.hooks.additionalModuleRuntimeRequirements.tap(
|
119
|
-
|
121
|
+
PLUGIN_NAME,
|
120
122
|
(module, set, context) => {
|
121
123
|
set.add(RuntimeGlobals.createScript);
|
122
124
|
}
|
@@ -35,9 +35,11 @@ const devtoolWarning = new RawSource(`/*
|
|
35
35
|
*/
|
36
36
|
`);
|
37
37
|
|
38
|
+
const PLUGIN_NAME = "EvalSourceMapDevToolPlugin";
|
39
|
+
|
38
40
|
class EvalSourceMapDevToolPlugin {
|
39
41
|
/**
|
40
|
-
* @param {SourceMapDevToolPluginOptions|string} inputOptions Options object
|
42
|
+
* @param {SourceMapDevToolPluginOptions | string} inputOptions Options object
|
41
43
|
*/
|
42
44
|
constructor(inputOptions) {
|
43
45
|
/** @type {SourceMapDevToolPluginOptions} */
|
@@ -67,160 +69,157 @@ class EvalSourceMapDevToolPlugin {
|
|
67
69
|
*/
|
68
70
|
apply(compiler) {
|
69
71
|
const options = this.options;
|
70
|
-
compiler.hooks.compilation.tap(
|
71
|
-
|
72
|
-
compilation
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
(
|
82
|
-
|
83
|
-
|
84
|
-
return cachedSource;
|
85
|
-
}
|
72
|
+
compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => {
|
73
|
+
const hooks = JavascriptModulesPlugin.getCompilationHooks(compilation);
|
74
|
+
new SourceMapDevToolModuleOptionsPlugin(options).apply(compilation);
|
75
|
+
const matchModule = ModuleFilenameHelpers.matchObject.bind(
|
76
|
+
ModuleFilenameHelpers,
|
77
|
+
options
|
78
|
+
);
|
79
|
+
hooks.renderModuleContent.tap(
|
80
|
+
PLUGIN_NAME,
|
81
|
+
(source, m, { chunk, runtimeTemplate, chunkGraph }) => {
|
82
|
+
const cachedSource = cache.get(source);
|
83
|
+
if (cachedSource !== undefined) {
|
84
|
+
return cachedSource;
|
85
|
+
}
|
86
86
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
87
|
+
/**
|
88
|
+
* @param {Source} r result
|
89
|
+
* @returns {Source} result
|
90
|
+
*/
|
91
|
+
const result = r => {
|
92
|
+
cache.set(source, r);
|
93
|
+
return r;
|
94
|
+
};
|
95
|
+
|
96
|
+
if (m instanceof NormalModule) {
|
97
|
+
const module = /** @type {NormalModule} */ (m);
|
98
|
+
if (!matchModule(module.resource)) {
|
99
|
+
return result(source);
|
100
|
+
}
|
101
|
+
} else if (m instanceof ConcatenatedModule) {
|
102
|
+
const concatModule = /** @type {ConcatenatedModule} */ (m);
|
103
|
+
if (concatModule.rootModule instanceof NormalModule) {
|
104
|
+
const module = /** @type {NormalModule} */ (
|
105
|
+
concatModule.rootModule
|
106
|
+
);
|
98
107
|
if (!matchModule(module.resource)) {
|
99
108
|
return result(source);
|
100
109
|
}
|
101
|
-
} else if (m instanceof ConcatenatedModule) {
|
102
|
-
const concatModule = /** @type {ConcatenatedModule} */ (m);
|
103
|
-
if (concatModule.rootModule instanceof NormalModule) {
|
104
|
-
const module = /** @type {NormalModule} */ (
|
105
|
-
concatModule.rootModule
|
106
|
-
);
|
107
|
-
if (!matchModule(module.resource)) {
|
108
|
-
return result(source);
|
109
|
-
}
|
110
|
-
} else {
|
111
|
-
return result(source);
|
112
|
-
}
|
113
110
|
} else {
|
114
111
|
return result(source);
|
115
112
|
}
|
113
|
+
} else {
|
114
|
+
return result(source);
|
115
|
+
}
|
116
116
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
117
|
+
const namespace = compilation.getPath(this.namespace, {
|
118
|
+
chunk
|
119
|
+
});
|
120
|
+
/** @type {SourceMap} */
|
121
|
+
let sourceMap;
|
122
|
+
let content;
|
123
|
+
if (source.sourceAndMap) {
|
124
|
+
const sourceAndMap = source.sourceAndMap(options);
|
125
|
+
sourceMap = /** @type {SourceMap} */ (sourceAndMap.map);
|
126
|
+
content = sourceAndMap.source;
|
127
|
+
} else {
|
128
|
+
sourceMap = /** @type {SourceMap} */ (source.map(options));
|
129
|
+
content = source.source();
|
130
|
+
}
|
131
|
+
if (!sourceMap) {
|
132
|
+
return result(source);
|
133
|
+
}
|
134
134
|
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
}
|
157
|
-
)
|
158
|
-
);
|
159
|
-
moduleFilenames = ModuleFilenameHelpers.replaceDuplicates(
|
160
|
-
moduleFilenames,
|
161
|
-
(filename, i, n) => {
|
162
|
-
for (let j = 0; j < n; j++) filename += "*";
|
163
|
-
return filename;
|
135
|
+
// Clone (flat) the sourcemap to ensure that the mutations below do not persist.
|
136
|
+
sourceMap = { ...sourceMap };
|
137
|
+
const context = /** @type {string} */ (compiler.options.context);
|
138
|
+
const root = compiler.root;
|
139
|
+
const modules = sourceMap.sources.map(source => {
|
140
|
+
if (!source.startsWith("webpack://")) return source;
|
141
|
+
source = makePathsAbsolute(context, source.slice(10), root);
|
142
|
+
const module = compilation.findModule(source);
|
143
|
+
return module || source;
|
144
|
+
});
|
145
|
+
let moduleFilenames = modules.map(module =>
|
146
|
+
ModuleFilenameHelpers.createFilename(
|
147
|
+
module,
|
148
|
+
{
|
149
|
+
moduleFilenameTemplate: this.moduleFilenameTemplate,
|
150
|
+
namespace
|
151
|
+
},
|
152
|
+
{
|
153
|
+
requestShortener: runtimeTemplate.requestShortener,
|
154
|
+
chunkGraph,
|
155
|
+
hashFunction: compilation.outputOptions.hashFunction
|
164
156
|
}
|
165
|
-
)
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
/** @type {ModuleId} */
|
173
|
-
(chunkGraph.getModuleId(m));
|
174
|
-
sourceMap.file =
|
175
|
-
typeof moduleId === "number" ? `${moduleId}.js` : moduleId;
|
176
|
-
|
177
|
-
if (options.debugIds) {
|
178
|
-
sourceMap.debugId = generateDebugId(content, sourceMap.file);
|
157
|
+
)
|
158
|
+
);
|
159
|
+
moduleFilenames = ModuleFilenameHelpers.replaceDuplicates(
|
160
|
+
moduleFilenames,
|
161
|
+
(filename, i, n) => {
|
162
|
+
for (let j = 0; j < n; j++) filename += "*";
|
163
|
+
return filename;
|
179
164
|
}
|
165
|
+
);
|
166
|
+
sourceMap.sources = moduleFilenames;
|
167
|
+
if (options.noSources) {
|
168
|
+
sourceMap.sourcesContent = undefined;
|
169
|
+
}
|
170
|
+
sourceMap.sourceRoot = options.sourceRoot || "";
|
171
|
+
const moduleId =
|
172
|
+
/** @type {ModuleId} */
|
173
|
+
(chunkGraph.getModuleId(m));
|
174
|
+
sourceMap.file =
|
175
|
+
typeof moduleId === "number" ? `${moduleId}.js` : moduleId;
|
180
176
|
|
181
|
-
|
182
|
-
|
183
|
-
`data:application/json;charset=utf-8;base64,${Buffer.from(
|
184
|
-
JSON.stringify(sourceMap),
|
185
|
-
"utf8"
|
186
|
-
).toString("base64")}`
|
187
|
-
)}\n//# sourceURL=webpack-internal:///${moduleId}\n`; // workaround for chrome bug
|
188
|
-
|
189
|
-
return result(
|
190
|
-
new RawSource(
|
191
|
-
`eval(${
|
192
|
-
compilation.outputOptions.trustedTypes
|
193
|
-
? `${RuntimeGlobals.createScript}(${JSON.stringify(
|
194
|
-
content + footer
|
195
|
-
)})`
|
196
|
-
: JSON.stringify(content + footer)
|
197
|
-
});`
|
198
|
-
)
|
199
|
-
);
|
177
|
+
if (options.debugIds) {
|
178
|
+
sourceMap.debugId = generateDebugId(content, sourceMap.file);
|
200
179
|
}
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
180
|
+
|
181
|
+
const footer = `${this.sourceMapComment.replace(
|
182
|
+
/\[url\]/g,
|
183
|
+
`data:application/json;charset=utf-8;base64,${Buffer.from(
|
184
|
+
JSON.stringify(sourceMap),
|
185
|
+
"utf8"
|
186
|
+
).toString("base64")}`
|
187
|
+
)}\n//# sourceURL=webpack-internal:///${moduleId}\n`; // workaround for chrome bug
|
188
|
+
|
189
|
+
return result(
|
190
|
+
new RawSource(
|
191
|
+
`eval(${
|
192
|
+
compilation.outputOptions.trustedTypes
|
193
|
+
? `${RuntimeGlobals.createScript}(${JSON.stringify(
|
194
|
+
content + footer
|
195
|
+
)})`
|
196
|
+
: JSON.stringify(content + footer)
|
197
|
+
});`
|
198
|
+
)
|
220
199
|
);
|
221
200
|
}
|
201
|
+
);
|
202
|
+
hooks.inlineInRuntimeBailout.tap(
|
203
|
+
"EvalDevToolModulePlugin",
|
204
|
+
() => "the eval-source-map devtool is used."
|
205
|
+
);
|
206
|
+
hooks.render.tap(
|
207
|
+
PLUGIN_NAME,
|
208
|
+
source => new ConcatSource(devtoolWarning, source)
|
209
|
+
);
|
210
|
+
hooks.chunkHash.tap(PLUGIN_NAME, (chunk, hash) => {
|
211
|
+
hash.update(PLUGIN_NAME);
|
212
|
+
hash.update("2");
|
213
|
+
});
|
214
|
+
if (compilation.outputOptions.trustedTypes) {
|
215
|
+
compilation.hooks.additionalModuleRuntimeRequirements.tap(
|
216
|
+
PLUGIN_NAME,
|
217
|
+
(module, set, context) => {
|
218
|
+
set.add(RuntimeGlobals.createScript);
|
219
|
+
}
|
220
|
+
);
|
222
221
|
}
|
223
|
-
);
|
222
|
+
});
|
224
223
|
}
|
225
224
|
}
|
226
225
|
|