webpack 5.92.1 → 5.93.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/lib/ContextModule.js +4 -2
- package/lib/DefinePlugin.js +1 -1
- package/lib/NormalModule.js +6 -1
- package/lib/UseStrictPlugin.js +8 -1
- package/lib/WebpackOptionsApply.js +5 -0
- package/lib/css/CssExportsGenerator.js +18 -21
- package/lib/css/CssGenerator.js +3 -11
- package/lib/dependencies/CssExportDependency.js +72 -9
- package/lib/dependencies/CssLocalIdentifierDependency.js +67 -20
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +2 -2
- package/lib/esm/ModuleChunkFormatPlugin.js +8 -9
- package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +1 -0
- package/lib/javascript/CommonJsChunkFormatPlugin.js +7 -9
- package/lib/javascript/JavascriptModulesPlugin.js +6 -1
- package/lib/library/AssignLibraryPlugin.js +1 -1
- package/lib/library/EnableLibraryPlugin.js +10 -1
- package/lib/library/ExportPropertyLibraryPlugin.js +8 -2
- package/lib/library/ModernModuleLibraryPlugin.js +142 -0
- package/lib/optimize/ConcatenatedModule.js +69 -18
- package/lib/optimize/ModuleConcatenationPlugin.js +2 -0
- package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +1 -0
- package/lib/sharing/ConsumeSharedModule.js +19 -14
- package/lib/sharing/ConsumeSharedRuntimeModule.js +104 -137
- package/lib/util/conventions.js +2 -2
- package/package.json +3 -3
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +16 -0
- package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -1
- package/schemas/plugins/asset/AssetInlineGeneratorOptions.check.js +1 -1
- package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +1 -1
- package/types.d.ts +15 -0
package/lib/ContextModule.js
CHANGED
@@ -190,8 +190,10 @@ class ContextModule extends Module {
|
|
190
190
|
* @returns {string} pretty RegExp
|
191
191
|
*/
|
192
192
|
_prettyRegExp(regexString, stripSlash = true) {
|
193
|
-
const str =
|
194
|
-
|
193
|
+
const str = stripSlash
|
194
|
+
? regexString.source + regexString.flags
|
195
|
+
: regexString + "";
|
196
|
+
return str.replace(/!/g, "%21").replace(/\|/g, "%7C");
|
195
197
|
}
|
196
198
|
|
197
199
|
_createIdentifier() {
|
package/lib/DefinePlugin.js
CHANGED
package/lib/NormalModule.js
CHANGED
@@ -867,9 +867,14 @@ class NormalModule extends Module {
|
|
867
867
|
return callback(error);
|
868
868
|
}
|
869
869
|
|
870
|
+
const isBinaryModule =
|
871
|
+
this.generatorOptions && this.generatorOptions.binary !== undefined
|
872
|
+
? this.generatorOptions.binary
|
873
|
+
: this.binary;
|
874
|
+
|
870
875
|
this._source = this.createSource(
|
871
876
|
/** @type {string} */ (options.context),
|
872
|
-
|
877
|
+
isBinaryModule ? asBuffer(source) : asString(source),
|
873
878
|
sourceMap,
|
874
879
|
compilation.compiler.root
|
875
880
|
);
|
package/lib/UseStrictPlugin.js
CHANGED
@@ -12,6 +12,7 @@ const {
|
|
12
12
|
} = require("./ModuleTypeConstants");
|
13
13
|
const ConstDependency = require("./dependencies/ConstDependency");
|
14
14
|
|
15
|
+
/** @typedef {import("../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
|
15
16
|
/** @typedef {import("./Compiler")} Compiler */
|
16
17
|
/** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */
|
17
18
|
/** @typedef {import("./Module").BuildInfo} BuildInfo */
|
@@ -32,8 +33,9 @@ class UseStrictPlugin {
|
|
32
33
|
(compilation, { normalModuleFactory }) => {
|
33
34
|
/**
|
34
35
|
* @param {JavascriptParser} parser the parser
|
36
|
+
* @param {JavascriptParserOptions} parserOptions the javascript parser options
|
35
37
|
*/
|
36
|
-
const handler = parser => {
|
38
|
+
const handler = (parser, parserOptions) => {
|
37
39
|
parser.hooks.program.tap(PLUGIN_NAME, ast => {
|
38
40
|
const firstNode = ast.body[0];
|
39
41
|
if (
|
@@ -54,6 +56,11 @@ class UseStrictPlugin {
|
|
54
56
|
/** @type {BuildInfo} */
|
55
57
|
(parser.state.module.buildInfo).strict = true;
|
56
58
|
}
|
59
|
+
if (parserOptions.overrideStrict) {
|
60
|
+
/** @type {BuildInfo} */
|
61
|
+
(parser.state.module.buildInfo).strict =
|
62
|
+
parserOptions.overrideStrict === "strict";
|
63
|
+
}
|
57
64
|
});
|
58
65
|
};
|
59
66
|
|
@@ -286,6 +286,11 @@ class WebpackOptionsApply extends OptionsApply {
|
|
286
286
|
"library type \"module\" is only allowed when 'experiments.outputModule' is enabled"
|
287
287
|
);
|
288
288
|
}
|
289
|
+
if (options.output.enabledLibraryTypes.includes("modern-module")) {
|
290
|
+
throw new Error(
|
291
|
+
"library type \"modern-module\" is only allowed when 'experiments.outputModule' is enabled"
|
292
|
+
);
|
293
|
+
}
|
289
294
|
if (options.externalsType === "module") {
|
290
295
|
throw new Error(
|
291
296
|
"'externalsType: \"module\"' is only allowed when 'experiments.outputModule' is enabled"
|
@@ -10,7 +10,6 @@ const { UsageState } = require("../ExportsInfo");
|
|
10
10
|
const Generator = require("../Generator");
|
11
11
|
const RuntimeGlobals = require("../RuntimeGlobals");
|
12
12
|
const Template = require("../Template");
|
13
|
-
const { cssExportConvention } = require("../util/conventions");
|
14
13
|
|
15
14
|
/** @typedef {import("webpack-sources").Source} Source */
|
16
15
|
/** @typedef {import("../../declarations/WebpackOptions").CssGeneratorExportsConvention} CssGeneratorExportsConvention */
|
@@ -135,20 +134,18 @@ class CssExportsGenerator extends Generator {
|
|
135
134
|
const source = new ConcatSource();
|
136
135
|
const usedIdentifiers = new Set();
|
137
136
|
for (const [name, v] of cssExportsData.exports) {
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
identifier = Template.toIdentifier(k + i);
|
143
|
-
}
|
144
|
-
usedIdentifiers.add(identifier);
|
145
|
-
generateContext.concatenationScope.registerExport(k, identifier);
|
146
|
-
source.add(
|
147
|
-
`${
|
148
|
-
generateContext.runtimeTemplate.supportsConst() ? "const" : "var"
|
149
|
-
} ${identifier} = ${JSON.stringify(v)};\n`
|
150
|
-
);
|
137
|
+
let identifier = Template.toIdentifier(name);
|
138
|
+
let i = 0;
|
139
|
+
while (usedIdentifiers.has(identifier)) {
|
140
|
+
identifier = Template.toIdentifier(name + i);
|
151
141
|
}
|
142
|
+
usedIdentifiers.add(identifier);
|
143
|
+
generateContext.concatenationScope.registerExport(name, identifier);
|
144
|
+
source.add(
|
145
|
+
`${
|
146
|
+
generateContext.runtimeTemplate.supportsConst() ? "const" : "var"
|
147
|
+
} ${identifier} = ${JSON.stringify(v)};\n`
|
148
|
+
);
|
152
149
|
}
|
153
150
|
return source;
|
154
151
|
} else {
|
@@ -163,16 +160,14 @@ class CssExportsGenerator extends Generator {
|
|
163
160
|
RuntimeGlobals.makeNamespaceObject
|
164
161
|
);
|
165
162
|
}
|
166
|
-
const
|
167
|
-
for (let [
|
168
|
-
|
169
|
-
newExports.push(`\t${JSON.stringify(name)}: ${JSON.stringify(v)}`);
|
170
|
-
}
|
163
|
+
const exports = [];
|
164
|
+
for (let [name, v] of cssExportsData.exports) {
|
165
|
+
exports.push(`\t${JSON.stringify(name)}: ${JSON.stringify(v)}`);
|
171
166
|
}
|
172
167
|
return new RawSource(
|
173
168
|
`${needNsObj ? `${RuntimeGlobals.makeNamespaceObject}(` : ""}${
|
174
169
|
module.moduleArgument
|
175
|
-
}.exports = {\n${
|
170
|
+
}.exports = {\n${exports.join(",\n")}\n}${needNsObj ? ")" : ""};`
|
176
171
|
);
|
177
172
|
}
|
178
173
|
}
|
@@ -198,7 +193,9 @@ class CssExportsGenerator extends Generator {
|
|
198
193
|
* @param {Hash} hash hash that will be modified
|
199
194
|
* @param {UpdateHashContext} updateHashContext context for updating hash
|
200
195
|
*/
|
201
|
-
updateHash(hash, { module }) {
|
196
|
+
updateHash(hash, { module }) {
|
197
|
+
hash.update(this.esModule.toString());
|
198
|
+
}
|
202
199
|
}
|
203
200
|
|
204
201
|
module.exports = CssExportsGenerator;
|
package/lib/css/CssGenerator.js
CHANGED
@@ -9,7 +9,6 @@ const { ReplaceSource } = require("webpack-sources");
|
|
9
9
|
const Generator = require("../Generator");
|
10
10
|
const InitFragment = require("../InitFragment");
|
11
11
|
const RuntimeGlobals = require("../RuntimeGlobals");
|
12
|
-
const { cssExportConvention } = require("../util/conventions");
|
13
12
|
|
14
13
|
/** @typedef {import("webpack-sources").Source} Source */
|
15
14
|
/** @typedef {import("../../declarations/WebpackOptions").CssGeneratorExportsConvention} CssGeneratorExportsConvention */
|
@@ -106,15 +105,6 @@ class CssGenerator extends Generator {
|
|
106
105
|
if (module.presentationalDependencies !== undefined)
|
107
106
|
module.presentationalDependencies.forEach(handleDependency);
|
108
107
|
|
109
|
-
if (cssExportsData.exports.size > 0) {
|
110
|
-
const newExports = new Map();
|
111
|
-
for (let [name, v] of cssExportsData.exports) {
|
112
|
-
for (let newName of cssExportConvention(name, this.convention)) {
|
113
|
-
newExports.set(newName, v);
|
114
|
-
}
|
115
|
-
}
|
116
|
-
cssExportsData.exports = newExports;
|
117
|
-
}
|
118
108
|
const data = generateContext.getData();
|
119
109
|
data.set("css-exports", cssExportsData);
|
120
110
|
|
@@ -148,7 +138,9 @@ class CssGenerator extends Generator {
|
|
148
138
|
* @param {Hash} hash hash that will be modified
|
149
139
|
* @param {UpdateHashContext} updateHashContext context for updating hash
|
150
140
|
*/
|
151
|
-
updateHash(hash, { module }) {
|
141
|
+
updateHash(hash, { module }) {
|
142
|
+
hash.update(this.esModule.toString());
|
143
|
+
}
|
152
144
|
}
|
153
145
|
|
154
146
|
module.exports = CssGenerator;
|
@@ -5,16 +5,23 @@
|
|
5
5
|
|
6
6
|
"use strict";
|
7
7
|
|
8
|
+
const { cssExportConvention } = require("../util/conventions");
|
8
9
|
const makeSerializable = require("../util/makeSerializable");
|
9
10
|
const NullDependency = require("./NullDependency");
|
10
11
|
|
11
12
|
/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
|
13
|
+
/** @typedef {import("../../declarations/WebpackOptions").CssGeneratorExportsConvention} CssGeneratorExportsConvention */
|
14
|
+
/** @typedef {import("../CssModule")} CssModule */
|
12
15
|
/** @typedef {import("../Dependency")} Dependency */
|
13
16
|
/** @typedef {import("../Dependency").ExportsSpec} ExportsSpec */
|
17
|
+
/** @typedef {import("../Dependency").UpdateHashContext} UpdateHashContext */
|
14
18
|
/** @typedef {import("../DependencyTemplate").CssDependencyTemplateContext} DependencyTemplateContext */
|
15
19
|
/** @typedef {import("../ModuleGraph")} ModuleGraph */
|
20
|
+
/** @typedef {import("../css/CssExportsGenerator")} CssExportsGenerator */
|
21
|
+
/** @typedef {import("../css/CssGenerator")} CssGenerator */
|
16
22
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
17
23
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
24
|
+
/** @typedef {import("../util/Hash")} Hash */
|
18
25
|
|
19
26
|
class CssExportDependency extends NullDependency {
|
20
27
|
/**
|
@@ -31,24 +38,60 @@ class CssExportDependency extends NullDependency {
|
|
31
38
|
return "css :export";
|
32
39
|
}
|
33
40
|
|
41
|
+
/**
|
42
|
+
* @param {string} name export name
|
43
|
+
* @param {CssGeneratorExportsConvention} convention convention of the export name
|
44
|
+
* @returns {string[]} convention results
|
45
|
+
*/
|
46
|
+
getExportsConventionNames(name, convention) {
|
47
|
+
if (this._conventionNames) {
|
48
|
+
return this._conventionNames;
|
49
|
+
}
|
50
|
+
this._conventionNames = cssExportConvention(name, convention);
|
51
|
+
return this._conventionNames;
|
52
|
+
}
|
53
|
+
|
34
54
|
/**
|
35
55
|
* Returns the exported names
|
36
56
|
* @param {ModuleGraph} moduleGraph module graph
|
37
57
|
* @returns {ExportsSpec | undefined} export names
|
38
58
|
*/
|
39
59
|
getExports(moduleGraph) {
|
40
|
-
const
|
60
|
+
const module = /** @type {CssModule} */ (moduleGraph.getParentModule(this));
|
61
|
+
const convention = /** @type {CssGenerator | CssExportsGenerator} */ (
|
62
|
+
module.generator
|
63
|
+
).convention;
|
64
|
+
const names = this.getExportsConventionNames(this.name, convention);
|
41
65
|
return {
|
42
|
-
exports:
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
}
|
47
|
-
],
|
66
|
+
exports: names.map(name => ({
|
67
|
+
name,
|
68
|
+
canMangle: true
|
69
|
+
})),
|
48
70
|
dependencies: undefined
|
49
71
|
};
|
50
72
|
}
|
51
73
|
|
74
|
+
/**
|
75
|
+
* Update the hash
|
76
|
+
* @param {Hash} hash hash to be updated
|
77
|
+
* @param {UpdateHashContext} context context
|
78
|
+
* @returns {void}
|
79
|
+
*/
|
80
|
+
updateHash(hash, { chunkGraph }) {
|
81
|
+
const module = /** @type {CssModule} */ (
|
82
|
+
chunkGraph.moduleGraph.getParentModule(this)
|
83
|
+
);
|
84
|
+
const generator = /** @type {CssGenerator | CssExportsGenerator} */ (
|
85
|
+
module.generator
|
86
|
+
);
|
87
|
+
const names = this.getExportsConventionNames(
|
88
|
+
this.name,
|
89
|
+
generator.convention
|
90
|
+
);
|
91
|
+
hash.update(`exportsConvention`);
|
92
|
+
hash.update(JSON.stringify(names));
|
93
|
+
}
|
94
|
+
|
52
95
|
/**
|
53
96
|
* @param {ObjectSerializerContext} context context
|
54
97
|
*/
|
@@ -79,9 +122,29 @@ CssExportDependency.Template = class CssExportDependencyTemplate extends (
|
|
79
122
|
* @param {DependencyTemplateContext} templateContext the context object
|
80
123
|
* @returns {void}
|
81
124
|
*/
|
82
|
-
apply(
|
125
|
+
apply(
|
126
|
+
dependency,
|
127
|
+
source,
|
128
|
+
{ cssExportsData, module: m, runtime, moduleGraph }
|
129
|
+
) {
|
83
130
|
const dep = /** @type {CssExportDependency} */ (dependency);
|
84
|
-
|
131
|
+
const module = /** @type {CssModule} */ (m);
|
132
|
+
const convention = /** @type {CssGenerator | CssExportsGenerator} */ (
|
133
|
+
module.generator
|
134
|
+
).convention;
|
135
|
+
const names = dep.getExportsConventionNames(dep.name, convention);
|
136
|
+
const usedNames = /** @type {string[]} */ (
|
137
|
+
names
|
138
|
+
.map(name =>
|
139
|
+
moduleGraph.getExportInfo(module, name).getUsedName(name, runtime)
|
140
|
+
)
|
141
|
+
.filter(Boolean)
|
142
|
+
);
|
143
|
+
if (usedNames.length === 0) return;
|
144
|
+
|
145
|
+
for (const used of usedNames) {
|
146
|
+
cssExportsData.exports.set(used, dep.value);
|
147
|
+
}
|
85
148
|
}
|
86
149
|
};
|
87
150
|
|
@@ -5,6 +5,7 @@
|
|
5
5
|
|
6
6
|
"use strict";
|
7
7
|
|
8
|
+
const { cssExportConvention } = require("../util/conventions");
|
8
9
|
const createHash = require("../util/createHash");
|
9
10
|
const { makePathsRelative } = require("../util/identifier");
|
10
11
|
const makeSerializable = require("../util/makeSerializable");
|
@@ -17,6 +18,7 @@ const NullDependency = require("./NullDependency");
|
|
17
18
|
/** @typedef {import("../CssModule")} CssModule */
|
18
19
|
/** @typedef {import("../Dependency")} Dependency */
|
19
20
|
/** @typedef {import("../Dependency").ExportsSpec} ExportsSpec */
|
21
|
+
/** @typedef {import("../Dependency").UpdateHashContext} UpdateHashContext */
|
20
22
|
/** @typedef {import("../DependencyTemplate").CssDependencyTemplateContext} DependencyTemplateContext */
|
21
23
|
/** @typedef {import("../ModuleGraph")} ModuleGraph */
|
22
24
|
/** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
|
@@ -25,6 +27,7 @@ const NullDependency = require("./NullDependency");
|
|
25
27
|
/** @typedef {import("../css/CssParser").Range} Range */
|
26
28
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
27
29
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
30
|
+
/** @typedef {import("../util/Hash")} Hash */
|
28
31
|
|
29
32
|
/**
|
30
33
|
* @param {string} local css local
|
@@ -88,24 +91,62 @@ class CssLocalIdentifierDependency extends NullDependency {
|
|
88
91
|
return "css local identifier";
|
89
92
|
}
|
90
93
|
|
94
|
+
/**
|
95
|
+
* @param {string} name export name
|
96
|
+
* @param {CssGeneratorExportsConvention} convention convention of the export name
|
97
|
+
* @returns {string[]} convention results
|
98
|
+
*/
|
99
|
+
getExportsConventionNames(name, convention) {
|
100
|
+
if (this._conventionNames) {
|
101
|
+
return this._conventionNames;
|
102
|
+
}
|
103
|
+
this._conventionNames = cssExportConvention(this.name, convention);
|
104
|
+
return this._conventionNames;
|
105
|
+
}
|
106
|
+
|
91
107
|
/**
|
92
108
|
* Returns the exported names
|
93
109
|
* @param {ModuleGraph} moduleGraph module graph
|
94
110
|
* @returns {ExportsSpec | undefined} export names
|
95
111
|
*/
|
96
112
|
getExports(moduleGraph) {
|
97
|
-
const
|
113
|
+
const module = /** @type {CssModule} */ (moduleGraph.getParentModule(this));
|
114
|
+
const convention = /** @type {CssGenerator | CssExportsGenerator} */ (
|
115
|
+
module.generator
|
116
|
+
).convention;
|
117
|
+
const names = this.getExportsConventionNames(this.name, convention);
|
98
118
|
return {
|
99
|
-
exports:
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
}
|
104
|
-
],
|
119
|
+
exports: names.map(name => ({
|
120
|
+
name,
|
121
|
+
canMangle: true
|
122
|
+
})),
|
105
123
|
dependencies: undefined
|
106
124
|
};
|
107
125
|
}
|
108
126
|
|
127
|
+
/**
|
128
|
+
* Update the hash
|
129
|
+
* @param {Hash} hash hash to be updated
|
130
|
+
* @param {UpdateHashContext} context context
|
131
|
+
* @returns {void}
|
132
|
+
*/
|
133
|
+
updateHash(hash, { chunkGraph }) {
|
134
|
+
const module = /** @type {CssModule} */ (
|
135
|
+
chunkGraph.moduleGraph.getParentModule(this)
|
136
|
+
);
|
137
|
+
const generator = /** @type {CssGenerator | CssExportsGenerator} */ (
|
138
|
+
module.generator
|
139
|
+
);
|
140
|
+
const names = this.getExportsConventionNames(
|
141
|
+
this.name,
|
142
|
+
generator.convention
|
143
|
+
);
|
144
|
+
hash.update(`exportsConvention`);
|
145
|
+
hash.update(JSON.stringify(names));
|
146
|
+
hash.update(`localIdentName`);
|
147
|
+
hash.update(generator.localIdentName);
|
148
|
+
}
|
149
|
+
|
109
150
|
/**
|
110
151
|
* @param {ObjectSerializerContext} context context
|
111
152
|
*/
|
@@ -158,7 +199,7 @@ CssLocalIdentifierDependency.Template = class CssLocalIdentifierDependencyTempla
|
|
158
199
|
dependency,
|
159
200
|
source,
|
160
201
|
{
|
161
|
-
module,
|
202
|
+
module: m,
|
162
203
|
moduleGraph,
|
163
204
|
chunkGraph,
|
164
205
|
runtime,
|
@@ -167,26 +208,32 @@ CssLocalIdentifierDependency.Template = class CssLocalIdentifierDependencyTempla
|
|
167
208
|
}
|
168
209
|
) {
|
169
210
|
const dep = /** @type {CssLocalIdentifierDependency} */ (dependency);
|
170
|
-
const
|
171
|
-
|
172
|
-
.
|
173
|
-
|
174
|
-
|
211
|
+
const module = /** @type {CssModule} */ (m);
|
212
|
+
const convention = /** @type {CssGenerator | CssExportsGenerator} */ (
|
213
|
+
module.generator
|
214
|
+
).convention;
|
215
|
+
const names = dep.getExportsConventionNames(dep.name, convention);
|
216
|
+
const usedNames = /** @type {string[]} */ (
|
217
|
+
names
|
218
|
+
.map(name =>
|
219
|
+
moduleGraph.getExportInfo(module, name).getUsedName(name, runtime)
|
220
|
+
)
|
221
|
+
.filter(Boolean)
|
222
|
+
);
|
223
|
+
if (usedNames.length === 0) return;
|
175
224
|
|
225
|
+
// use the first usedName to generate localIdent, it's shorter when mangle exports enabled
|
176
226
|
const localIdent =
|
177
227
|
dep.prefix +
|
178
|
-
getLocalIdent(
|
179
|
-
used,
|
180
|
-
/** @type {CssModule} */ (module),
|
181
|
-
chunkGraph,
|
182
|
-
runtimeTemplate
|
183
|
-
);
|
228
|
+
getLocalIdent(usedNames[0], module, chunkGraph, runtimeTemplate);
|
184
229
|
source.replace(
|
185
230
|
dep.range[0],
|
186
231
|
dep.range[1] - 1,
|
187
232
|
escapeCssIdentifier(localIdent, dep.prefix)
|
188
233
|
);
|
189
|
-
|
234
|
+
for (const used of usedNames) {
|
235
|
+
cssExportsData.exports.set(used, localIdent);
|
236
|
+
}
|
190
237
|
}
|
191
238
|
};
|
192
239
|
|
@@ -344,13 +344,13 @@ HarmonyImportSpecifierDependency.Template = class HarmonyImportSpecifierDependen
|
|
344
344
|
}
|
345
345
|
|
346
346
|
if (dep.referencedPropertiesInDestructuring) {
|
347
|
+
const prefixedIds = ids[0] === "default" ? ids.slice(1) : ids;
|
347
348
|
for (let {
|
348
349
|
id,
|
349
350
|
shorthand,
|
350
351
|
range
|
351
352
|
} of dep.referencedPropertiesInDestructuring) {
|
352
|
-
const concatedIds =
|
353
|
-
if (concatedIds[0] === "default") concatedIds.shift();
|
353
|
+
const concatedIds = prefixedIds.concat([id]);
|
354
354
|
const module = moduleGraph.getModule(dep);
|
355
355
|
const used = moduleGraph
|
356
356
|
.getExportsInfo(module)
|
@@ -16,6 +16,7 @@ const {
|
|
16
16
|
getChunkFilenameTemplate
|
17
17
|
} = require("../javascript/JavascriptModulesPlugin");
|
18
18
|
const { updateHashForEntryStartup } = require("../javascript/StartupHelpers");
|
19
|
+
const { getUndoPath } = require("../util/identifier");
|
19
20
|
|
20
21
|
/** @typedef {import("../Chunk")} Chunk */
|
21
22
|
/** @typedef {import("../Compiler")} Compiler */
|
@@ -86,11 +87,9 @@ class ModuleChunkFormatPlugin {
|
|
86
87
|
contentHashType: "javascript"
|
87
88
|
}
|
88
89
|
)
|
90
|
+
.replace(/^\/+/g, "")
|
89
91
|
.split("/");
|
90
92
|
|
91
|
-
// remove filename, we only need the directory
|
92
|
-
currentOutputName.pop();
|
93
|
-
|
94
93
|
/**
|
95
94
|
* @param {Chunk} chunk the chunk
|
96
95
|
* @returns {string} the relative path
|
@@ -108,22 +107,22 @@ class ModuleChunkFormatPlugin {
|
|
108
107
|
contentHashType: "javascript"
|
109
108
|
}
|
110
109
|
)
|
110
|
+
.replace(/^\/+/g, "")
|
111
111
|
.split("/");
|
112
112
|
|
113
|
-
// remove common parts
|
113
|
+
// remove common parts except filename
|
114
114
|
while (
|
115
|
-
baseOutputName.length >
|
116
|
-
chunkOutputName.length >
|
115
|
+
baseOutputName.length > 1 &&
|
116
|
+
chunkOutputName.length > 1 &&
|
117
117
|
baseOutputName[0] === chunkOutputName[0]
|
118
118
|
) {
|
119
119
|
baseOutputName.shift();
|
120
120
|
chunkOutputName.shift();
|
121
121
|
}
|
122
|
+
const last = chunkOutputName.join("/");
|
122
123
|
// create final path
|
123
124
|
return (
|
124
|
-
(baseOutputName.
|
125
|
-
? "../".repeat(baseOutputName.length)
|
126
|
-
: "./") + chunkOutputName.join("/")
|
125
|
+
getUndoPath(baseOutputName.join("/"), last, true) + last
|
127
126
|
);
|
128
127
|
};
|
129
128
|
|
@@ -33,6 +33,7 @@ class ArrayPushCallbackChunkFormatPlugin {
|
|
33
33
|
if (chunk.hasRuntime()) return;
|
34
34
|
if (chunkGraph.getNumberOfEntryModules(chunk) > 0) {
|
35
35
|
set.add(RuntimeGlobals.onChunksLoaded);
|
36
|
+
set.add(RuntimeGlobals.exports);
|
36
37
|
set.add(RuntimeGlobals.require);
|
37
38
|
}
|
38
39
|
set.add(RuntimeGlobals.chunkCallback);
|
@@ -8,6 +8,7 @@
|
|
8
8
|
const { ConcatSource, RawSource } = require("webpack-sources");
|
9
9
|
const RuntimeGlobals = require("../RuntimeGlobals");
|
10
10
|
const Template = require("../Template");
|
11
|
+
const { getUndoPath } = require("../util/identifier");
|
11
12
|
const {
|
12
13
|
getChunkFilenameTemplate,
|
13
14
|
getCompilationHooks
|
@@ -79,6 +80,7 @@ class CommonJsChunkFormatPlugin {
|
|
79
80
|
contentHashType: "javascript"
|
80
81
|
}
|
81
82
|
)
|
83
|
+
.replace(/^\/+/g, "")
|
82
84
|
.split("/");
|
83
85
|
const runtimeOutputName = compilation
|
84
86
|
.getPath(
|
@@ -91,26 +93,22 @@ class CommonJsChunkFormatPlugin {
|
|
91
93
|
contentHashType: "javascript"
|
92
94
|
}
|
93
95
|
)
|
96
|
+
.replace(/^\/+/g, "")
|
94
97
|
.split("/");
|
95
98
|
|
96
|
-
// remove filename, we only need the directory
|
97
|
-
currentOutputName.pop();
|
98
|
-
|
99
99
|
// remove common parts
|
100
100
|
while (
|
101
|
-
currentOutputName.length >
|
102
|
-
runtimeOutputName.length >
|
101
|
+
currentOutputName.length > 1 &&
|
102
|
+
runtimeOutputName.length > 1 &&
|
103
103
|
currentOutputName[0] === runtimeOutputName[0]
|
104
104
|
) {
|
105
105
|
currentOutputName.shift();
|
106
106
|
runtimeOutputName.shift();
|
107
107
|
}
|
108
|
-
|
108
|
+
const last = runtimeOutputName.join("/");
|
109
109
|
// create final path
|
110
110
|
const runtimePath =
|
111
|
-
(currentOutputName.
|
112
|
-
? "../".repeat(currentOutputName.length)
|
113
|
-
: "./") + runtimeOutputName.join("/");
|
111
|
+
getUndoPath(currentOutputName.join("/"), last, true) + last;
|
114
112
|
|
115
113
|
const entrySource = new ConcatSource();
|
116
114
|
entrySource.add(
|
@@ -435,6 +435,7 @@ class JavascriptModulesPlugin {
|
|
435
435
|
chunkGraph.hasChunkEntryDependentChunks(chunk)
|
436
436
|
) {
|
437
437
|
set.add(RuntimeGlobals.onChunksLoaded);
|
438
|
+
set.add(RuntimeGlobals.exports);
|
438
439
|
set.add(RuntimeGlobals.require);
|
439
440
|
}
|
440
441
|
}
|
@@ -821,7 +822,11 @@ class JavascriptModulesPlugin {
|
|
821
822
|
}
|
822
823
|
const lastInlinedModule = last(inlinedModules);
|
823
824
|
const startupSource = new ConcatSource();
|
824
|
-
|
825
|
+
|
826
|
+
if (runtimeRequirements.has(RuntimeGlobals.exports)) {
|
827
|
+
startupSource.add(`var ${RuntimeGlobals.exports} = {};\n`);
|
828
|
+
}
|
829
|
+
|
825
830
|
const renamedInlinedModule = this.renameInlineModule(
|
826
831
|
allModules,
|
827
832
|
renderContext,
|
@@ -78,7 +78,8 @@ class EnableLibraryPlugin {
|
|
78
78
|
const ExportPropertyTemplatePlugin = require("./ExportPropertyLibraryPlugin");
|
79
79
|
new ExportPropertyTemplatePlugin({
|
80
80
|
type,
|
81
|
-
nsObjectUsed:
|
81
|
+
nsObjectUsed: !["module", "modern-module"].includes(type),
|
82
|
+
runtimeExportsUsed: type !== "modern-module"
|
82
83
|
}).apply(compiler);
|
83
84
|
};
|
84
85
|
switch (type) {
|
@@ -238,6 +239,14 @@ class EnableLibraryPlugin {
|
|
238
239
|
}).apply(compiler);
|
239
240
|
break;
|
240
241
|
}
|
242
|
+
case "modern-module": {
|
243
|
+
enableExportProperty();
|
244
|
+
const ModernModuleLibraryPlugin = require("./ModernModuleLibraryPlugin");
|
245
|
+
new ModernModuleLibraryPlugin({
|
246
|
+
type
|
247
|
+
}).apply(compiler);
|
248
|
+
break;
|
249
|
+
}
|
241
250
|
default:
|
242
251
|
throw new Error(`Unsupported library type ${type}.
|
243
252
|
Plugins which provide custom library types must call EnableLibraryPlugin.setEnabled(compiler, type) to disable this error.`);
|