webpack 5.105.2 → 5.105.4
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/CleanPlugin.js +1 -0
- package/lib/Compilation.js +10 -8
- package/lib/ContextModule.js +14 -8
- package/lib/Dependency.js +1 -1
- package/lib/EnvironmentNotSupportAsyncWarning.js +1 -0
- package/lib/EvalDevToolModulePlugin.js +3 -0
- package/lib/EvalSourceMapDevToolPlugin.js +8 -1
- package/lib/ExportsInfo.js +0 -30
- package/lib/ExternalModule.js +2 -2
- package/lib/Module.js +45 -5
- package/lib/ModuleGraphConnection.js +0 -9
- package/lib/MultiStats.js +5 -5
- package/lib/RuntimeModule.js +18 -1
- package/lib/SourceMapDevToolModuleOptionsPlugin.js +1 -0
- package/lib/SourceMapDevToolPlugin.js +10 -2
- package/lib/Stats.js +3 -2
- package/lib/WebpackOptionsApply.js +13 -3
- package/lib/asset/AssetModulesPlugin.js +16 -1
- package/lib/asset/RawDataUrlModule.js +5 -1
- package/lib/container/RemoteModule.js +18 -1
- package/lib/css/CssGenerator.js +13 -6
- package/lib/css/CssModulesPlugin.js +7 -0
- package/lib/dependencies/CommonJsExportRequireDependency.js +4 -0
- package/lib/dependencies/CommonJsImportsParserPlugin.js +314 -508
- package/lib/dependencies/CreateRequireParserPlugin.js +356 -0
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +4 -8
- package/lib/dependencies/HarmonyImportDependency.js +30 -0
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +128 -224
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +11 -5
- package/lib/dependencies/HarmonyModulesPlugin.js +4 -0
- package/lib/dependencies/ImportParserPlugin.js +1 -11
- package/lib/dependencies/ImportPhase.js +4 -0
- package/lib/javascript/JavascriptModulesPlugin.js +75 -22
- package/lib/javascript/JavascriptParser.js +2 -2
- package/lib/optimize/ConcatenatedModule.js +3 -0
- package/lib/optimize/ModuleConcatenationPlugin.js +4 -1
- package/lib/performance/AssetsOverSizeLimitWarning.js +1 -0
- package/lib/performance/EntrypointsOverSizeLimitWarning.js +1 -0
- package/lib/performance/SizeLimitsPlugin.js +1 -0
- package/lib/runtime/ToBinaryRuntimeModule.js +14 -6
- package/lib/sharing/ConsumeSharedModule.js +18 -1
- package/lib/util/AppendOnlyStackedSet.js +22 -1
- package/lib/util/findGraphRoots.js +79 -109
- package/package.json +14 -11
- package/types.d.ts +243 -99
package/lib/CleanPlugin.js
CHANGED
package/lib/Compilation.js
CHANGED
|
@@ -4019,7 +4019,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
|
|
|
4019
4019
|
* @param {string | ChunkGroupOptions} groupOptions options for the chunk group
|
|
4020
4020
|
* @param {Module=} module the module the references the chunk group
|
|
4021
4021
|
* @param {DependencyLocation=} loc the location from with the chunk group is referenced (inside of module)
|
|
4022
|
-
* @param {string=} request the request from which the
|
|
4022
|
+
* @param {string=} request the request from which the chunk group is referenced
|
|
4023
4023
|
* @returns {ChunkGroup} the new or existing chunk group
|
|
4024
4024
|
*/
|
|
4025
4025
|
addChunkInGroup(groupOptions, module, loc, request) {
|
|
@@ -4067,7 +4067,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
|
|
|
4067
4067
|
* @param {EntryOptions} options options for the entrypoint
|
|
4068
4068
|
* @param {Module} module the module the references the chunk group
|
|
4069
4069
|
* @param {DependencyLocation} loc the location from with the chunk group is referenced (inside of module)
|
|
4070
|
-
* @param {string} request the request from which the
|
|
4070
|
+
* @param {string} request the request from which the chunk group is referenced
|
|
4071
4071
|
* @returns {Entrypoint} the new or existing entrypoint
|
|
4072
4072
|
*/
|
|
4073
4073
|
addAsyncEntrypoint(options, module, loc, request) {
|
|
@@ -4531,12 +4531,14 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
|
|
|
4531
4531
|
(e) => e.chunks[e.chunks.length - 1]
|
|
4532
4532
|
)
|
|
4533
4533
|
)) {
|
|
4534
|
-
const otherInfo =
|
|
4535
|
-
|
|
4536
|
-
|
|
4537
|
-
otherInfo
|
|
4538
|
-
|
|
4539
|
-
|
|
4534
|
+
const otherInfo = runtimeChunksMap.get(other);
|
|
4535
|
+
// other may be a non-runtime chunk (e.g. worker chunk)
|
|
4536
|
+
// when you have a worker chunk in your app.js (new Worker(...)) and as a separate entry point
|
|
4537
|
+
if (otherInfo) {
|
|
4538
|
+
otherInfo.referencedBy.push(info);
|
|
4539
|
+
info.remaining++;
|
|
4540
|
+
remaining++;
|
|
4541
|
+
}
|
|
4540
4542
|
}
|
|
4541
4543
|
}
|
|
4542
4544
|
/** @type {Chunk[]} */
|
package/lib/ContextModule.js
CHANGED
|
@@ -119,6 +119,7 @@ const makeSerializable = require("./util/makeSerializable");
|
|
|
119
119
|
|
|
120
120
|
/** @typedef {Record<ModuleId, FakeMapType>} FakeMap */
|
|
121
121
|
/** @typedef {Record<string, ModuleId>} UserRequestMap */
|
|
122
|
+
/** @typedef {Record<ModuleId, ModuleId[]>} UserRequestsMap */
|
|
122
123
|
|
|
123
124
|
class ContextModule extends Module {
|
|
124
125
|
/**
|
|
@@ -711,7 +712,7 @@ class ContextModule extends Module {
|
|
|
711
712
|
/**
|
|
712
713
|
* @param {Dependency[]} dependencies all dependencies
|
|
713
714
|
* @param {ChunkGraph} chunkGraph chunk graph
|
|
714
|
-
* @returns {
|
|
715
|
+
* @returns {UserRequestsMap} map with user requests
|
|
715
716
|
*/
|
|
716
717
|
getModuleDeferredAsyncDepsMap(dependencies, chunkGraph) {
|
|
717
718
|
const moduleGraph = chunkGraph.moduleGraph;
|
|
@@ -726,6 +727,7 @@ class ContextModule extends Module {
|
|
|
726
727
|
)
|
|
727
728
|
.filter(Boolean)
|
|
728
729
|
.sort(comparator);
|
|
730
|
+
/** @type {UserRequestsMap} */
|
|
729
731
|
const map = Object.create(null);
|
|
730
732
|
for (const module of sortedModules) {
|
|
731
733
|
if (!(/** @type {BuildMeta} */ (module.buildMeta).async)) {
|
|
@@ -740,7 +742,7 @@ class ContextModule extends Module {
|
|
|
740
742
|
}
|
|
741
743
|
|
|
742
744
|
/**
|
|
743
|
-
* @param {false |
|
|
745
|
+
* @param {false | UserRequestsMap} asyncDepsMap fake map
|
|
744
746
|
* @returns {string} async deps map init statement
|
|
745
747
|
*/
|
|
746
748
|
getModuleDeferredAsyncDepsMapInitStatement(asyncDepsMap) {
|
|
@@ -1168,12 +1170,16 @@ function webpackAsyncContext(req) {
|
|
|
1168
1170
|
])});
|
|
1169
1171
|
}`
|
|
1170
1172
|
: `function webpackAsyncContext(req) {
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1173
|
+
try {
|
|
1174
|
+
if(!${RuntimeGlobals.hasOwnProperty}(map, req)) {
|
|
1175
|
+
return Promise.resolve().then(${runtimeTemplate.basicFunction("", [
|
|
1176
|
+
'var e = new Error("Cannot find module \'" + req + "\'");',
|
|
1177
|
+
"e.code = 'MODULE_NOT_FOUND';",
|
|
1178
|
+
"throw e;"
|
|
1179
|
+
])});
|
|
1180
|
+
}
|
|
1181
|
+
} catch(err) {
|
|
1182
|
+
return Promise.reject(err);
|
|
1177
1183
|
}
|
|
1178
1184
|
|
|
1179
1185
|
var ids = map[req], id = ids[0];
|
package/lib/Dependency.js
CHANGED
|
@@ -227,7 +227,7 @@ class Dependency {
|
|
|
227
227
|
*/
|
|
228
228
|
getReference(moduleGraph) {
|
|
229
229
|
throw new Error(
|
|
230
|
-
"Dependency.getReference was removed in favor of Dependency.getReferencedExports, ModuleGraph.getModule
|
|
230
|
+
"Dependency.getReference was removed in favor of Dependency.getReferencedExports, ModuleGraph.getModule, ModuleGraph.getConnection(), and ModuleGraphConnection.getActiveState(runtime)"
|
|
231
231
|
);
|
|
232
232
|
}
|
|
233
233
|
|
|
@@ -43,8 +43,11 @@ class EvalDevToolModulePlugin {
|
|
|
43
43
|
* @param {EvalDevToolModulePluginOptions=} options options
|
|
44
44
|
*/
|
|
45
45
|
constructor(options = {}) {
|
|
46
|
+
/** @type {DevtoolNamespace} */
|
|
46
47
|
this.namespace = options.namespace || "";
|
|
48
|
+
/** @type {string} */
|
|
47
49
|
this.sourceUrlComment = options.sourceUrlComment || "\n//# sourceURL=[url]";
|
|
50
|
+
/** @type {DevtoolModuleFilenameTemplate} */
|
|
48
51
|
this.moduleFilenameTemplate =
|
|
49
52
|
options.moduleFilenameTemplate ||
|
|
50
53
|
"webpack://[namespace]/[resourcePath]?[loaders]";
|
|
@@ -17,10 +17,13 @@ const { makePathsAbsolute } = require("./util/identifier");
|
|
|
17
17
|
|
|
18
18
|
/** @typedef {import("webpack-sources").RawSourceMap} RawSourceMap */
|
|
19
19
|
/** @typedef {import("webpack-sources").Source} Source */
|
|
20
|
+
/** @typedef {import("../declarations/WebpackOptions").DevtoolNamespace} DevtoolNamespace */
|
|
21
|
+
/** @typedef {import("../declarations/WebpackOptions").DevtoolModuleFilenameTemplate} DevtoolModuleFilenameTemplate */
|
|
20
22
|
/** @typedef {import("../declarations/plugins/SourceMapDevToolPlugin").SourceMapDevToolPluginOptions} SourceMapDevToolPluginOptions */
|
|
21
23
|
/** @typedef {import("../declarations/plugins/SourceMapDevToolPlugin").Rules} Rules */
|
|
22
|
-
/** @typedef {import("./ChunkGraph").ModuleId} ModuleId */
|
|
23
24
|
/** @typedef {import("./Compiler")} Compiler */
|
|
25
|
+
/** @typedef {import("./ChunkGraph").ModuleId} ModuleId */
|
|
26
|
+
/** @typedef {import("./TemplatedPathPlugin").TemplatePath} TemplatePath */
|
|
24
27
|
|
|
25
28
|
/** @type {WeakMap<Source, Source>} */
|
|
26
29
|
const cache = new WeakMap();
|
|
@@ -51,14 +54,18 @@ class EvalSourceMapDevToolPlugin {
|
|
|
51
54
|
} else {
|
|
52
55
|
options = inputOptions;
|
|
53
56
|
}
|
|
57
|
+
/** @type {string} */
|
|
54
58
|
this.sourceMapComment =
|
|
55
59
|
options.append && typeof options.append !== "function"
|
|
56
60
|
? options.append
|
|
57
61
|
: "//# sourceURL=[module]\n//# sourceMappingURL=[url]";
|
|
62
|
+
/** @type {DevtoolModuleFilenameTemplate} */
|
|
58
63
|
this.moduleFilenameTemplate =
|
|
59
64
|
options.moduleFilenameTemplate ||
|
|
60
65
|
"webpack://[namespace]/[resource-path]?[hash]";
|
|
66
|
+
/** @type {DevtoolNamespace} */
|
|
61
67
|
this.namespace = options.namespace || "";
|
|
68
|
+
/** @type {SourceMapDevToolPluginOptions} */
|
|
62
69
|
this.options = options;
|
|
63
70
|
}
|
|
64
71
|
|
package/lib/ExportsInfo.js
CHANGED
|
@@ -933,36 +933,6 @@ class ExportInfo {
|
|
|
933
933
|
this._maxTarget = undefined;
|
|
934
934
|
}
|
|
935
935
|
|
|
936
|
-
// TODO webpack 5 remove
|
|
937
|
-
/**
|
|
938
|
-
* @private
|
|
939
|
-
* @param {EXPECTED_ANY} v v
|
|
940
|
-
*/
|
|
941
|
-
set used(v) {
|
|
942
|
-
throw new Error("REMOVED");
|
|
943
|
-
}
|
|
944
|
-
|
|
945
|
-
// TODO webpack 5 remove
|
|
946
|
-
/** @private */
|
|
947
|
-
get used() {
|
|
948
|
-
throw new Error("REMOVED");
|
|
949
|
-
}
|
|
950
|
-
|
|
951
|
-
// TODO webpack 5 remove
|
|
952
|
-
/**
|
|
953
|
-
* @private
|
|
954
|
-
* @param {EXPECTED_ANY} v v
|
|
955
|
-
*/
|
|
956
|
-
set usedName(v) {
|
|
957
|
-
throw new Error("REMOVED");
|
|
958
|
-
}
|
|
959
|
-
|
|
960
|
-
// TODO webpack 5 remove
|
|
961
|
-
/** @private */
|
|
962
|
-
get usedName() {
|
|
963
|
-
throw new Error("REMOVED");
|
|
964
|
-
}
|
|
965
|
-
|
|
966
936
|
get canMangle() {
|
|
967
937
|
switch (this.canMangleProvide) {
|
|
968
938
|
case undefined:
|
package/lib/ExternalModule.js
CHANGED
|
@@ -995,7 +995,7 @@ class ExternalModule extends Module {
|
|
|
995
995
|
);
|
|
996
996
|
/** @type {CodeGenerationResultData} */
|
|
997
997
|
const data = new Map();
|
|
998
|
-
data.set("url", { javascript: request });
|
|
998
|
+
data.set("url", { javascript: /** @type {string} */ (request) });
|
|
999
999
|
return { sources, runtimeRequirements: RUNTIME_REQUIREMENTS, data };
|
|
1000
1000
|
}
|
|
1001
1001
|
case "css-url": {
|
|
@@ -1003,7 +1003,7 @@ class ExternalModule extends Module {
|
|
|
1003
1003
|
const sources = new Map();
|
|
1004
1004
|
/** @type {CodeGenerationResultData} */
|
|
1005
1005
|
const data = new Map();
|
|
1006
|
-
data.set("url", { "css-url": request });
|
|
1006
|
+
data.set("url", { "css-url": /** @type {string} */ (request) });
|
|
1007
1007
|
return { sources, runtimeRequirements: RUNTIME_REQUIREMENTS, data };
|
|
1008
1008
|
}
|
|
1009
1009
|
case "css-import": {
|
package/lib/Module.js
CHANGED
|
@@ -80,6 +80,8 @@ const makeSerializable = require("./util/makeSerializable");
|
|
|
80
80
|
/** @typedef {KnownSourceType | string} SourceType */
|
|
81
81
|
/** @typedef {ReadonlySet<SourceType>} SourceTypes */
|
|
82
82
|
|
|
83
|
+
/** @typedef {ReadonlySet<typeof JAVASCRIPT_TYPE | string>} BasicSourceTypes */
|
|
84
|
+
|
|
83
85
|
// TODO webpack 6: compilation will be required in CodeGenerationContext
|
|
84
86
|
/**
|
|
85
87
|
* @typedef {object} CodeGenerationContext
|
|
@@ -104,11 +106,36 @@ const makeSerializable = require("./util/makeSerializable");
|
|
|
104
106
|
/** @typedef {Set<string>} RuntimeRequirements */
|
|
105
107
|
/** @typedef {ReadonlySet<string>} ReadOnlyRuntimeRequirements */
|
|
106
108
|
|
|
107
|
-
/**
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
109
|
+
/**
|
|
110
|
+
* @typedef {object} AllCodeGenerationSchemas
|
|
111
|
+
* @property {Set<string>} topLevelDeclarations top level declarations for javascript modules
|
|
112
|
+
* @property {InitFragment<EXPECTED_ANY>[]} chunkInitFragments chunk init fragments for javascript modules
|
|
113
|
+
* @property {{ javascript?: string, ["css-url"]?: string }} url url for css and javascript modules
|
|
114
|
+
* @property {string} filename a filename for asset modules
|
|
115
|
+
* @property {AssetInfo} assetInfo an asset info for asset modules
|
|
116
|
+
* @property {string} fullContentHash a full content hash for asset modules
|
|
117
|
+
* @property {[{ shareScope: string, initStage: number, init: string }]} share-init share-init for modules federation
|
|
118
|
+
*/
|
|
119
|
+
|
|
120
|
+
/* eslint-disable jsdoc/type-formatting */
|
|
121
|
+
/**
|
|
122
|
+
* @template {string} K
|
|
123
|
+
* @typedef {K extends keyof AllCodeGenerationSchemas ? AllCodeGenerationSchemas[K] : EXPECTED_ANY} CodeGenValue
|
|
124
|
+
*/
|
|
125
|
+
/* eslint-enable jsdoc/type-formatting */
|
|
126
|
+
|
|
127
|
+
/* eslint-disable jsdoc/require-template */
|
|
128
|
+
/**
|
|
129
|
+
* @typedef {object} CodeGenMapOverloads
|
|
130
|
+
* @property {<K extends string>(key: K) => CodeGenValue<K> | undefined} get
|
|
131
|
+
* @property {<K extends string>(key: K, value: CodeGenValue<K>) => CodeGenerationResultData} set
|
|
132
|
+
* @property {<K extends string>(key: K) => boolean} has
|
|
133
|
+
* @property {<K extends string>(key: K) => boolean} delete
|
|
134
|
+
*/
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* @typedef {Omit<Map<string, EXPECTED_ANY>, "get" | "set" | "has" | "delete"> & CodeGenMapOverloads} CodeGenerationResultData
|
|
138
|
+
*/
|
|
112
139
|
|
|
113
140
|
/** @typedef {Map<SourceType, Source>} Sources */
|
|
114
141
|
|
|
@@ -941,6 +968,19 @@ class Module extends DependenciesBlock {
|
|
|
941
968
|
return JAVASCRIPT_TYPES;
|
|
942
969
|
}
|
|
943
970
|
|
|
971
|
+
/**
|
|
972
|
+
* Basic source types are high-level categories like javascript, css, webassembly, etc.
|
|
973
|
+
* We only have built-in knowledge about the javascript basic type here; other basic types may be
|
|
974
|
+
* added or changed over time by generators and do not need to be handled or detected here.
|
|
975
|
+
*
|
|
976
|
+
* Some modules, e.g. RemoteModule, may return non-basic source types like "remote" and "share-init"
|
|
977
|
+
* from getSourceTypes(), but their generated output is still JavaScript, i.e. their basic type is JS.
|
|
978
|
+
* @returns {BasicSourceTypes} types available (do not mutate)
|
|
979
|
+
*/
|
|
980
|
+
getSourceBasicTypes() {
|
|
981
|
+
return this.getSourceTypes();
|
|
982
|
+
}
|
|
983
|
+
|
|
944
984
|
/**
|
|
945
985
|
* @abstract
|
|
946
986
|
* @deprecated Use codeGeneration() instead
|
|
@@ -184,15 +184,6 @@ class ModuleGraphConnection {
|
|
|
184
184
|
this.conditional = false;
|
|
185
185
|
this._active = value;
|
|
186
186
|
}
|
|
187
|
-
|
|
188
|
-
// TODO webpack 5 remove
|
|
189
|
-
get active() {
|
|
190
|
-
throw new Error("Use getActiveState instead");
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
set active(value) {
|
|
194
|
-
throw new Error("Use setActive instead");
|
|
195
|
-
}
|
|
196
187
|
}
|
|
197
188
|
|
|
198
189
|
/** @typedef {typeof TRANSITIVE_ONLY} TRANSITIVE_ONLY */
|
package/lib/MultiStats.js
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
const identifierUtils = require("./util/identifier");
|
|
9
9
|
|
|
10
10
|
/** @typedef {import("../declarations/WebpackOptions").StatsOptions} StatsOptions */
|
|
11
|
+
/** @typedef {import("../declarations/WebpackOptions").StatsValue} StatsValue */
|
|
11
12
|
/** @typedef {import("./Compilation").CreateStatsOptionsContext} CreateStatsOptionsContext */
|
|
12
13
|
/** @typedef {import("./Compilation").NormalizedStatsOptions} NormalizedStatsOptions */
|
|
13
14
|
/** @typedef {import("./Stats")} Stats */
|
|
@@ -25,8 +26,7 @@ const indent = (str, prefix) => {
|
|
|
25
26
|
return prefix + rem;
|
|
26
27
|
};
|
|
27
28
|
|
|
28
|
-
/** @typedef {
|
|
29
|
-
/** @typedef {Omit<StatsOptions, "children"> & { children?: ChildrenStatsOptions | ChildrenStatsOptions[] }} MultiStatsOptions */
|
|
29
|
+
/** @typedef {StatsOptions} MultiStatsOptions */
|
|
30
30
|
/** @typedef {{ version: boolean, hash: boolean, errorsCount: boolean, warningsCount: boolean, errors: boolean, warnings: boolean, children: NormalizedStatsOptions[] }} ChildOptions */
|
|
31
31
|
|
|
32
32
|
class MultiStats {
|
|
@@ -56,7 +56,7 @@ class MultiStats {
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
/**
|
|
59
|
-
* @param {undefined |
|
|
59
|
+
* @param {undefined | StatsValue} options stats options
|
|
60
60
|
* @param {CreateStatsOptionsContext} context context
|
|
61
61
|
* @returns {ChildOptions} context context
|
|
62
62
|
*/
|
|
@@ -109,7 +109,7 @@ class MultiStats {
|
|
|
109
109
|
}
|
|
110
110
|
|
|
111
111
|
/**
|
|
112
|
-
* @param {
|
|
112
|
+
* @param {StatsValue=} options stats options
|
|
113
113
|
* @returns {StatsCompilation} json output
|
|
114
114
|
*/
|
|
115
115
|
toJson(options) {
|
|
@@ -184,7 +184,7 @@ class MultiStats {
|
|
|
184
184
|
}
|
|
185
185
|
|
|
186
186
|
/**
|
|
187
|
-
* @param {
|
|
187
|
+
* @param {StatsValue=} options stats options
|
|
188
188
|
* @returns {string} string output
|
|
189
189
|
*/
|
|
190
190
|
toString(options) {
|
package/lib/RuntimeModule.js
CHANGED
|
@@ -8,7 +8,10 @@
|
|
|
8
8
|
const { RawSource } = require("webpack-sources");
|
|
9
9
|
const OriginalSource = require("webpack-sources").OriginalSource;
|
|
10
10
|
const Module = require("./Module");
|
|
11
|
-
const {
|
|
11
|
+
const {
|
|
12
|
+
JAVASCRIPT_TYPES,
|
|
13
|
+
RUNTIME_TYPES
|
|
14
|
+
} = require("./ModuleSourceTypeConstants");
|
|
12
15
|
const { WEBPACK_MODULE_TYPE_RUNTIME } = require("./ModuleTypeConstants");
|
|
13
16
|
|
|
14
17
|
/** @typedef {import("./config/defaults").WebpackOptionsNormalizedWithDefaults} WebpackOptions */
|
|
@@ -29,6 +32,7 @@ const { WEBPACK_MODULE_TYPE_RUNTIME } = require("./ModuleTypeConstants");
|
|
|
29
32
|
/** @typedef {import("./ResolverFactory").ResolverWithOptions} ResolverWithOptions */
|
|
30
33
|
/** @typedef {import("./util/Hash")} Hash */
|
|
31
34
|
/** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
|
|
35
|
+
/** @typedef {import("./Module").BasicSourceTypes} BasicSourceTypes */
|
|
32
36
|
|
|
33
37
|
class RuntimeModule extends Module {
|
|
34
38
|
/**
|
|
@@ -138,6 +142,19 @@ class RuntimeModule extends Module {
|
|
|
138
142
|
return RUNTIME_TYPES;
|
|
139
143
|
}
|
|
140
144
|
|
|
145
|
+
/**
|
|
146
|
+
* Basic source types are high-level categories like javascript, css, webassembly, etc.
|
|
147
|
+
* We only have built-in knowledge about the javascript basic type here; other basic types may be
|
|
148
|
+
* added or changed over time by generators and do not need to be handled or detected here.
|
|
149
|
+
*
|
|
150
|
+
* Some modules, e.g. RemoteModule, may return non-basic source types like "remote" and "share-init"
|
|
151
|
+
* from getSourceTypes(), but their generated output is still JavaScript, i.e. their basic type is JS.
|
|
152
|
+
* @returns {BasicSourceTypes} types available (do not mutate)
|
|
153
|
+
*/
|
|
154
|
+
getSourceBasicTypes() {
|
|
155
|
+
return JAVASCRIPT_TYPES;
|
|
156
|
+
}
|
|
157
|
+
|
|
141
158
|
/**
|
|
142
159
|
* @param {CodeGenerationContext} context context for code generation
|
|
143
160
|
* @returns {CodeGenerationResult} result
|
|
@@ -19,6 +19,9 @@ const { makePathsAbsolute } = require("./util/identifier");
|
|
|
19
19
|
|
|
20
20
|
/** @typedef {import("webpack-sources").MapOptions} MapOptions */
|
|
21
21
|
/** @typedef {import("webpack-sources").Source} Source */
|
|
22
|
+
/** @typedef {import("../declarations/WebpackOptions").DevtoolNamespace} DevtoolNamespace */
|
|
23
|
+
/** @typedef {import("../declarations/WebpackOptions").DevtoolModuleFilenameTemplate} DevtoolModuleFilenameTemplate */
|
|
24
|
+
/** @typedef {import("../declarations/WebpackOptions").DevtoolFallbackModuleFilenameTemplate} DevtoolFallbackModuleFilenameTemplate */
|
|
22
25
|
/** @typedef {import("../declarations/plugins/SourceMapDevToolPlugin").SourceMapDevToolPluginOptions} SourceMapDevToolPluginOptions */
|
|
23
26
|
/** @typedef {import("../declarations/plugins/SourceMapDevToolPlugin").Rules} Rules */
|
|
24
27
|
/** @typedef {import("./CacheFacade").ItemCacheFacade} ItemCacheFacade */
|
|
@@ -140,19 +143,24 @@ class SourceMapDevToolPlugin {
|
|
|
140
143
|
constructor(options = {}) {
|
|
141
144
|
validate(options);
|
|
142
145
|
|
|
143
|
-
|
|
144
|
-
|
|
146
|
+
/** @type {undefined | null | false | string} */
|
|
147
|
+
this.sourceMapFilename = options.filename;
|
|
148
|
+
/** @type {false | TemplatePath} */
|
|
145
149
|
this.sourceMappingURLComment =
|
|
146
150
|
options.append === false
|
|
147
151
|
? false
|
|
148
152
|
: // eslint-disable-next-line no-useless-concat
|
|
149
153
|
options.append || "\n//# source" + "MappingURL=[url]";
|
|
154
|
+
/** @type {DevtoolModuleFilenameTemplate} */
|
|
150
155
|
this.moduleFilenameTemplate =
|
|
151
156
|
options.moduleFilenameTemplate || "webpack://[namespace]/[resourcePath]";
|
|
157
|
+
/** @type {DevtoolFallbackModuleFilenameTemplate} */
|
|
152
158
|
this.fallbackModuleFilenameTemplate =
|
|
153
159
|
options.fallbackModuleFilenameTemplate ||
|
|
154
160
|
"webpack://[namespace]/[resourcePath]?[hash]";
|
|
161
|
+
/** @type {DevtoolNamespace} */
|
|
155
162
|
this.namespace = options.namespace || "";
|
|
163
|
+
/** @type {SourceMapDevToolPluginOptions} */
|
|
156
164
|
this.options = options;
|
|
157
165
|
}
|
|
158
166
|
|
package/lib/Stats.js
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
"use strict";
|
|
7
7
|
|
|
8
8
|
/** @typedef {import("../declarations/WebpackOptions").StatsOptions} StatsOptions */
|
|
9
|
+
/** @typedef {import("../declarations/WebpackOptions").StatsValue} StatsValue */
|
|
9
10
|
/** @typedef {import("./Compilation")} Compilation */
|
|
10
11
|
/** @typedef {import("./stats/DefaultStatsFactoryPlugin").StatsCompilation} StatsCompilation */
|
|
11
12
|
|
|
@@ -50,7 +51,7 @@ class Stats {
|
|
|
50
51
|
}
|
|
51
52
|
|
|
52
53
|
/**
|
|
53
|
-
* @param {
|
|
54
|
+
* @param {StatsValue=} options stats options
|
|
54
55
|
* @returns {StatsCompilation} json output
|
|
55
56
|
*/
|
|
56
57
|
toJson(options) {
|
|
@@ -66,7 +67,7 @@ class Stats {
|
|
|
66
67
|
}
|
|
67
68
|
|
|
68
69
|
/**
|
|
69
|
-
* @param {
|
|
70
|
+
* @param {StatsValue=} options stats options
|
|
70
71
|
* @returns {string} string output
|
|
71
72
|
*/
|
|
72
73
|
toString(options) {
|
|
@@ -60,6 +60,7 @@ const URLPlugin = require("./dependencies/URLPlugin");
|
|
|
60
60
|
const WorkerPlugin = require("./dependencies/WorkerPlugin");
|
|
61
61
|
|
|
62
62
|
const JavascriptModulesPlugin = require("./javascript/JavascriptModulesPlugin");
|
|
63
|
+
const JavascriptParser = require("./javascript/JavascriptParser");
|
|
63
64
|
|
|
64
65
|
const JsonModulesPlugin = require("./json/JsonModulesPlugin");
|
|
65
66
|
|
|
@@ -371,7 +372,9 @@ class WebpackOptionsApply extends OptionsApply {
|
|
|
371
372
|
|
|
372
373
|
new JavascriptModulesPlugin().apply(compiler);
|
|
373
374
|
new JsonModulesPlugin().apply(compiler);
|
|
374
|
-
new AssetModulesPlugin(
|
|
375
|
+
new AssetModulesPlugin({
|
|
376
|
+
sideEffectFree: options.experiments.futureDefaults
|
|
377
|
+
}).apply(compiler);
|
|
375
378
|
|
|
376
379
|
if (!options.experiments.outputModule) {
|
|
377
380
|
if (options.output.module) {
|
|
@@ -483,11 +486,18 @@ class WebpackOptionsApply extends OptionsApply {
|
|
|
483
486
|
new HttpUriPlugin(httpOptions).apply(compiler);
|
|
484
487
|
}
|
|
485
488
|
|
|
486
|
-
if (
|
|
487
|
-
|
|
489
|
+
if (
|
|
490
|
+
options.experiments.deferImport &&
|
|
491
|
+
!(
|
|
492
|
+
/** @type {typeof JavascriptParser & { __importPhasesExtended?: true }} */
|
|
493
|
+
(JavascriptParser).__importPhasesExtended
|
|
494
|
+
)
|
|
495
|
+
) {
|
|
488
496
|
const importPhases = require("acorn-import-phases");
|
|
489
497
|
|
|
490
498
|
JavascriptParser.extend(importPhases({ source: false }));
|
|
499
|
+
/** @type {typeof JavascriptParser & { __importPhasesExtended?: true }} */
|
|
500
|
+
(JavascriptParser).__importPhasesExtended = true;
|
|
491
501
|
}
|
|
492
502
|
|
|
493
503
|
new EntryOptionPlugin().apply(compiler);
|
|
@@ -86,7 +86,19 @@ const getNormalModule = memoize(() => require("../NormalModule"));
|
|
|
86
86
|
const type = ASSET_MODULE_TYPE;
|
|
87
87
|
const PLUGIN_NAME = "AssetModulesPlugin";
|
|
88
88
|
|
|
89
|
+
/**
|
|
90
|
+
* @typedef {object} AssetModulesPluginOptions
|
|
91
|
+
* @property {boolean=} sideEffectFree
|
|
92
|
+
*/
|
|
93
|
+
|
|
89
94
|
class AssetModulesPlugin {
|
|
95
|
+
/**
|
|
96
|
+
* @param {AssetModulesPluginOptions} options options
|
|
97
|
+
*/
|
|
98
|
+
constructor(options) {
|
|
99
|
+
this.options = options;
|
|
100
|
+
}
|
|
101
|
+
|
|
90
102
|
/**
|
|
91
103
|
* Apply the plugin
|
|
92
104
|
* @param {Compiler} compiler the compiler instance
|
|
@@ -112,7 +124,10 @@ class AssetModulesPlugin {
|
|
|
112
124
|
/** @type {NormalModuleCreateData} */
|
|
113
125
|
(createData)
|
|
114
126
|
);
|
|
115
|
-
|
|
127
|
+
if (this.options.sideEffectFree) {
|
|
128
|
+
module.factoryMeta = { sideEffectFree: true };
|
|
129
|
+
}
|
|
130
|
+
|
|
116
131
|
return module;
|
|
117
132
|
});
|
|
118
133
|
}
|
|
@@ -42,9 +42,13 @@ class RawDataUrlModule extends Module {
|
|
|
42
42
|
*/
|
|
43
43
|
constructor(url, identifier, readableIdentifier) {
|
|
44
44
|
super(ASSET_MODULE_TYPE_RAW_DATA_URL, null);
|
|
45
|
+
/** @type {string} */
|
|
45
46
|
this.url = url;
|
|
47
|
+
/** @type {Buffer | undefined} */
|
|
46
48
|
this.urlBuffer = url ? Buffer.from(url) : undefined;
|
|
47
|
-
|
|
49
|
+
/** @type {string} */
|
|
50
|
+
this.identifierStr = identifier;
|
|
51
|
+
/** @type {string} */
|
|
48
52
|
this.readableIdentifierStr = readableIdentifier || this.identifierStr;
|
|
49
53
|
}
|
|
50
54
|
|
|
@@ -7,7 +7,10 @@
|
|
|
7
7
|
|
|
8
8
|
const { RawSource } = require("webpack-sources");
|
|
9
9
|
const Module = require("../Module");
|
|
10
|
-
const {
|
|
10
|
+
const {
|
|
11
|
+
JAVASCRIPT_TYPES,
|
|
12
|
+
REMOTE_AND_SHARE_INIT_TYPES
|
|
13
|
+
} = require("../ModuleSourceTypeConstants");
|
|
11
14
|
const { WEBPACK_MODULE_TYPE_REMOTE } = require("../ModuleTypeConstants");
|
|
12
15
|
const RuntimeGlobals = require("../RuntimeGlobals");
|
|
13
16
|
const makeSerializable = require("../util/makeSerializable");
|
|
@@ -34,6 +37,7 @@ const RemoteToExternalDependency = require("./RemoteToExternalDependency");
|
|
|
34
37
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
|
35
38
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
|
36
39
|
/** @typedef {import("../util/fs").InputFileSystem} InputFileSystem */
|
|
40
|
+
/** @typedef {import("../Module").BasicSourceTypes} BasicSourceTypes */
|
|
37
41
|
|
|
38
42
|
const RUNTIME_REQUIREMENTS = new Set([RuntimeGlobals.module]);
|
|
39
43
|
|
|
@@ -137,6 +141,19 @@ class RemoteModule extends Module {
|
|
|
137
141
|
return REMOTE_AND_SHARE_INIT_TYPES;
|
|
138
142
|
}
|
|
139
143
|
|
|
144
|
+
/**
|
|
145
|
+
* Basic source types are high-level categories like javascript, css, webassembly, etc.
|
|
146
|
+
* We only have built-in knowledge about the javascript basic type here; other basic types may be
|
|
147
|
+
* added or changed over time by generators and do not need to be handled or detected here.
|
|
148
|
+
*
|
|
149
|
+
* Some modules, e.g. RemoteModule, may return non-basic source types like "remote" and "share-init"
|
|
150
|
+
* from getSourceTypes(), but their generated output is still JavaScript, i.e. their basic type is JS.
|
|
151
|
+
* @returns {BasicSourceTypes} types available (do not mutate)
|
|
152
|
+
*/
|
|
153
|
+
getSourceBasicTypes() {
|
|
154
|
+
return JAVASCRIPT_TYPES;
|
|
155
|
+
}
|
|
156
|
+
|
|
140
157
|
/**
|
|
141
158
|
* @param {ModuleGraph} moduleGraph the module graph
|
|
142
159
|
* @param {boolean | undefined} strict the importing module is strict
|
package/lib/css/CssGenerator.js
CHANGED
|
@@ -19,7 +19,7 @@ const {
|
|
|
19
19
|
const RuntimeGlobals = require("../RuntimeGlobals");
|
|
20
20
|
const Template = require("../Template");
|
|
21
21
|
const CssImportDependency = require("../dependencies/CssImportDependency");
|
|
22
|
-
const
|
|
22
|
+
const HarmonyImportSideEffectDependency = require("../dependencies/HarmonyImportSideEffectDependency");
|
|
23
23
|
const { getUndoPath } = require("../util/identifier");
|
|
24
24
|
const memoize = require("../util/memoize");
|
|
25
25
|
|
|
@@ -470,22 +470,27 @@ class CssGenerator extends Generator {
|
|
|
470
470
|
getTypes(module) {
|
|
471
471
|
const exportType = /** @type {BuildMeta} */ (module.buildMeta).exportType;
|
|
472
472
|
const sourceTypes = new Set();
|
|
473
|
+
|
|
473
474
|
const connections = this._moduleGraph.getIncomingConnections(module);
|
|
474
475
|
|
|
475
|
-
let isEntryModule = false;
|
|
476
476
|
for (const connection of connections) {
|
|
477
|
-
if (connection.dependency instanceof EntryDependency) {
|
|
478
|
-
isEntryModule = true;
|
|
479
|
-
}
|
|
480
477
|
if (
|
|
481
478
|
exportType === "link" &&
|
|
482
479
|
connection.dependency instanceof CssImportDependency
|
|
483
480
|
) {
|
|
484
481
|
continue;
|
|
485
482
|
}
|
|
483
|
+
|
|
484
|
+
// when no hmr required, css module js output contains no sideEffects at all
|
|
485
|
+
// js sideeffect connection doesn't require js type output
|
|
486
|
+
if (connection.dependency instanceof HarmonyImportSideEffectDependency) {
|
|
487
|
+
continue;
|
|
488
|
+
}
|
|
489
|
+
|
|
486
490
|
if (!connection.originModule) {
|
|
487
491
|
continue;
|
|
488
492
|
}
|
|
493
|
+
|
|
489
494
|
if (connection.originModule.type.split("/")[0] !== CSS_TYPE) {
|
|
490
495
|
sourceTypes.add(JAVASCRIPT_TYPE);
|
|
491
496
|
} else {
|
|
@@ -503,7 +508,7 @@ class CssGenerator extends Generator {
|
|
|
503
508
|
}
|
|
504
509
|
}
|
|
505
510
|
if (this._generatesJsOnly(module)) {
|
|
506
|
-
if (sourceTypes.has(JAVASCRIPT_TYPE)
|
|
511
|
+
if (sourceTypes.has(JAVASCRIPT_TYPE)) {
|
|
507
512
|
return JAVASCRIPT_TYPES;
|
|
508
513
|
}
|
|
509
514
|
return new Set();
|
|
@@ -578,3 +583,5 @@ class CssGenerator extends Generator {
|
|
|
578
583
|
}
|
|
579
584
|
|
|
580
585
|
module.exports = CssGenerator;
|
|
586
|
+
|
|
587
|
+
module.exports = CssGenerator;
|