webpack 5.64.2 → 5.66.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/CacheFacade.js +2 -9
- package/lib/Chunk.js +2 -0
- package/lib/Compilation.js +79 -38
- package/lib/Dependency.js +10 -0
- package/lib/DependencyTemplate.js +9 -0
- package/lib/ExternalModule.js +93 -53
- package/lib/Generator.js +2 -0
- package/lib/Module.js +24 -1
- package/lib/ModuleFilenameHelpers.js +5 -1
- package/lib/NormalModule.js +3 -1
- package/lib/RuntimeGlobals.js +11 -1
- package/lib/RuntimePlugin.js +25 -0
- package/lib/RuntimeTemplate.js +113 -2
- package/lib/Template.js +2 -1
- package/lib/WatchIgnorePlugin.js +14 -1
- package/lib/Watching.js +32 -18
- package/lib/WebpackOptionsApply.js +43 -2
- package/lib/asset/AssetGenerator.js +10 -7
- package/lib/asset/RawDataUrlModule.js +145 -0
- package/lib/config/browserslistTargetHandler.js +38 -1
- package/lib/config/defaults.js +60 -4
- package/lib/config/target.js +10 -0
- package/lib/container/ContainerEntryModule.js +4 -3
- package/lib/css/CssGenerator.js +106 -0
- package/lib/css/CssLoadingRuntimeModule.js +393 -0
- package/lib/css/CssModulesPlugin.js +444 -0
- package/lib/css/CssParser.js +618 -0
- package/lib/css/walkCssTokens.js +659 -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/URLDependency.js +3 -8
- package/lib/esm/ModuleChunkFormatPlugin.js +74 -49
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +1 -1
- package/lib/hmr/lazyCompilationBackend.js +3 -1
- package/lib/index.js +3 -0
- package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +2 -2
- package/lib/javascript/ChunkHelpers.js +33 -0
- package/lib/javascript/JavascriptGenerator.js +1 -0
- package/lib/javascript/JavascriptParser.js +16 -8
- package/lib/javascript/StartupHelpers.js +4 -28
- package/lib/library/AssignLibraryPlugin.js +31 -13
- package/lib/library/EnableLibraryPlugin.js +11 -0
- package/lib/node/NodeWatchFileSystem.js +85 -31
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +1 -1
- package/lib/node/RequireChunkLoadingRuntimeModule.js +1 -1
- package/lib/optimize/ConcatenatedModule.js +10 -4
- package/lib/sharing/ConsumeSharedModule.js +4 -0
- package/lib/sharing/ConsumeSharedRuntimeModule.js +25 -4
- package/lib/stats/DefaultStatsPrinterPlugin.js +1 -1
- package/lib/util/create-schema-validation.js +9 -2
- package/lib/util/extractUrlAndGlobal.js +3 -0
- package/lib/util/fs.js +10 -0
- package/lib/util/hash/xxhash64.js +2 -2
- package/lib/util/internalSerializables.js +11 -0
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +3 -3
- package/lib/webpack.js +9 -1
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +3 -2
- package/package.json +4 -4
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +63 -1
- 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/AssetParserOptions.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/types.d.ts +147 -21
package/lib/RuntimeTemplate.js
CHANGED
@@ -16,6 +16,7 @@ const { forEachRuntime, subtractRuntime } = require("./util/runtime");
|
|
16
16
|
/** @typedef {import("../declarations/WebpackOptions").OutputNormalized} OutputOptions */
|
17
17
|
/** @typedef {import("./AsyncDependenciesBlock")} AsyncDependenciesBlock */
|
18
18
|
/** @typedef {import("./ChunkGraph")} ChunkGraph */
|
19
|
+
/** @typedef {import("./CodeGenerationResults")} CodeGenerationResults */
|
19
20
|
/** @typedef {import("./Compilation")} Compilation */
|
20
21
|
/** @typedef {import("./Dependency")} Dependency */
|
21
22
|
/** @typedef {import("./Module")} Module */
|
@@ -50,6 +51,27 @@ Module has these incoming connections: ${Array.from(
|
|
50
51
|
).join("")}`;
|
51
52
|
};
|
52
53
|
|
54
|
+
/**
|
55
|
+
* @param {string|undefined} definition global object definition
|
56
|
+
* @returns {string} save to use global object
|
57
|
+
*/
|
58
|
+
function getGlobalObject(definition) {
|
59
|
+
if (!definition) return definition;
|
60
|
+
const trimmed = definition.trim();
|
61
|
+
|
62
|
+
if (
|
63
|
+
// identifier, we do not need real identifier regarding ECMAScript/Unicode
|
64
|
+
trimmed.match(/^[_\p{L}][_0-9\p{L}]*$/iu) ||
|
65
|
+
// iife
|
66
|
+
// call expression
|
67
|
+
// expression in parentheses
|
68
|
+
trimmed.match(/^([_\p{L}][_0-9\p{L}]*)?\(.*\)$/iu)
|
69
|
+
)
|
70
|
+
return trimmed;
|
71
|
+
|
72
|
+
return `Object(${trimmed})`;
|
73
|
+
}
|
74
|
+
|
53
75
|
class RuntimeTemplate {
|
54
76
|
/**
|
55
77
|
* @param {Compilation} compilation the compilation
|
@@ -60,6 +82,7 @@ class RuntimeTemplate {
|
|
60
82
|
this.compilation = compilation;
|
61
83
|
this.outputOptions = outputOptions || {};
|
62
84
|
this.requestShortener = requestShortener;
|
85
|
+
this.globalObject = getGlobalObject(outputOptions.globalObject);
|
63
86
|
}
|
64
87
|
|
65
88
|
isIIFE() {
|
@@ -78,6 +101,10 @@ class RuntimeTemplate {
|
|
78
101
|
return this.outputOptions.environment.arrowFunction;
|
79
102
|
}
|
80
103
|
|
104
|
+
supportsOptionalChaining() {
|
105
|
+
return this.outputOptions.environment.optionalChaining;
|
106
|
+
}
|
107
|
+
|
81
108
|
supportsForOf() {
|
82
109
|
return this.outputOptions.environment.forOf;
|
83
110
|
}
|
@@ -99,8 +126,7 @@ class RuntimeTemplate {
|
|
99
126
|
}
|
100
127
|
|
101
128
|
supportTemplateLiteral() {
|
102
|
-
|
103
|
-
return false;
|
129
|
+
return this.outputOptions.environment.templateLiteral;
|
104
130
|
}
|
105
131
|
|
106
132
|
returningFunction(returnValue, args = "") {
|
@@ -115,6 +141,71 @@ class RuntimeTemplate {
|
|
115
141
|
: `function(${args}) {\n${Template.indent(body)}\n}`;
|
116
142
|
}
|
117
143
|
|
144
|
+
/**
|
145
|
+
* @param {Array<string|{expr: string}>} args args
|
146
|
+
* @returns {string} result expression
|
147
|
+
*/
|
148
|
+
concatenation(...args) {
|
149
|
+
const len = args.length;
|
150
|
+
|
151
|
+
if (len === 2) return this._es5Concatenation(args);
|
152
|
+
if (len === 0) return '""';
|
153
|
+
if (len === 1) {
|
154
|
+
return typeof args[0] === "string"
|
155
|
+
? JSON.stringify(args[0])
|
156
|
+
: `"" + ${args[0].expr}`;
|
157
|
+
}
|
158
|
+
if (!this.supportTemplateLiteral()) return this._es5Concatenation(args);
|
159
|
+
|
160
|
+
// cost comparison between template literal and concatenation:
|
161
|
+
// both need equal surroundings: `xxx` vs "xxx"
|
162
|
+
// template literal has constant cost of 3 chars for each expression
|
163
|
+
// es5 concatenation has cost of 3 + n chars for n expressions in row
|
164
|
+
// when a es5 concatenation ends with an expression it reduces cost by 3
|
165
|
+
// when a es5 concatenation starts with an single expression it reduces cost by 3
|
166
|
+
// e. g. `${a}${b}${c}` (3*3 = 9) is longer than ""+a+b+c ((3+3)-3 = 3)
|
167
|
+
// e. g. `x${a}x${b}x${c}x` (3*3 = 9) is shorter than "x"+a+"x"+b+"x"+c+"x" (4+4+4 = 12)
|
168
|
+
|
169
|
+
let templateCost = 0;
|
170
|
+
let concatenationCost = 0;
|
171
|
+
|
172
|
+
let lastWasExpr = false;
|
173
|
+
for (const arg of args) {
|
174
|
+
const isExpr = typeof arg !== "string";
|
175
|
+
if (isExpr) {
|
176
|
+
templateCost += 3;
|
177
|
+
concatenationCost += lastWasExpr ? 1 : 4;
|
178
|
+
}
|
179
|
+
lastWasExpr = isExpr;
|
180
|
+
}
|
181
|
+
if (lastWasExpr) concatenationCost -= 3;
|
182
|
+
if (typeof args[0] !== "string" && typeof args[1] === "string")
|
183
|
+
concatenationCost -= 3;
|
184
|
+
|
185
|
+
if (concatenationCost <= templateCost) return this._es5Concatenation(args);
|
186
|
+
|
187
|
+
return `\`${args
|
188
|
+
.map(arg => (typeof arg === "string" ? arg : `\${${arg.expr}}`))
|
189
|
+
.join("")}\``;
|
190
|
+
}
|
191
|
+
|
192
|
+
/**
|
193
|
+
* @param {Array<string|{expr: string}>} args args (len >= 2)
|
194
|
+
* @returns {string} result expression
|
195
|
+
* @private
|
196
|
+
*/
|
197
|
+
_es5Concatenation(args) {
|
198
|
+
const str = args
|
199
|
+
.map(arg => (typeof arg === "string" ? JSON.stringify(arg) : arg.expr))
|
200
|
+
.join(" + ");
|
201
|
+
|
202
|
+
// when the first two args are expression, we need to prepend "" + to force string
|
203
|
+
// concatenation instead of number addition.
|
204
|
+
return typeof args[0] !== "string" && typeof args[1] !== "string"
|
205
|
+
? `"" + ${str}`
|
206
|
+
: str;
|
207
|
+
}
|
208
|
+
|
118
209
|
expressionFunction(expression, args = "") {
|
119
210
|
return this.supportsArrowFunction()
|
120
211
|
? `(${args}) => (${expression})`
|
@@ -924,6 +1015,26 @@ class RuntimeTemplate {
|
|
924
1015
|
runtimeRequirements.add(RuntimeGlobals.exports);
|
925
1016
|
return `${RuntimeGlobals.makeNamespaceObject}(${exportsArgument});\n`;
|
926
1017
|
}
|
1018
|
+
|
1019
|
+
/**
|
1020
|
+
* @param {Object} options options object
|
1021
|
+
* @param {Module} options.module the module
|
1022
|
+
* @param {string} options.publicPath the public path
|
1023
|
+
* @param {RuntimeSpec=} options.runtime runtime
|
1024
|
+
* @param {CodeGenerationResults} options.codeGenerationResults the code generation results
|
1025
|
+
* @returns {string} the url of the asset
|
1026
|
+
*/
|
1027
|
+
assetUrl({ publicPath, runtime, module, codeGenerationResults }) {
|
1028
|
+
if (!module) {
|
1029
|
+
return "data:,";
|
1030
|
+
}
|
1031
|
+
const codeGen = codeGenerationResults.get(module, runtime);
|
1032
|
+
const { data } = codeGen;
|
1033
|
+
const url = data.get("url");
|
1034
|
+
if (url) return url;
|
1035
|
+
const filename = data.get("filename");
|
1036
|
+
return publicPath + filename;
|
1037
|
+
}
|
927
1038
|
}
|
928
1039
|
|
929
1040
|
module.exports = RuntimeTemplate;
|
package/lib/Template.js
CHANGED
@@ -370,7 +370,8 @@ class Template {
|
|
370
370
|
dependencyTemplates: renderContext.dependencyTemplates,
|
371
371
|
moduleGraph: renderContext.moduleGraph,
|
372
372
|
runtimeTemplate: renderContext.runtimeTemplate,
|
373
|
-
runtime: renderContext.chunk.runtime
|
373
|
+
runtime: renderContext.chunk.runtime,
|
374
|
+
codeGenerationResults
|
374
375
|
});
|
375
376
|
if (!codeGenResult) continue;
|
376
377
|
runtimeSource = codeGenResult.sources.get("runtime");
|
package/lib/WatchIgnorePlugin.js
CHANGED
@@ -87,7 +87,20 @@ class IgnoringWatchFileSystem {
|
|
87
87
|
fileTimestamps.set(path, IGNORE_TIME_ENTRY);
|
88
88
|
}
|
89
89
|
return fileTimestamps;
|
90
|
-
}
|
90
|
+
},
|
91
|
+
getInfo:
|
92
|
+
watcher.getInfo &&
|
93
|
+
(() => {
|
94
|
+
const info = watcher.getInfo();
|
95
|
+
const { fileTimeInfoEntries, contextTimeInfoEntries } = info;
|
96
|
+
for (const path of ignoredFiles) {
|
97
|
+
fileTimeInfoEntries.set(path, IGNORE_TIME_ENTRY);
|
98
|
+
}
|
99
|
+
for (const path of ignoredDirs) {
|
100
|
+
contextTimeInfoEntries.set(path, IGNORE_TIME_ENTRY);
|
101
|
+
}
|
102
|
+
return info;
|
103
|
+
})
|
91
104
|
};
|
92
105
|
}
|
93
106
|
}
|
package/lib/Watching.js
CHANGED
@@ -49,7 +49,7 @@ class Watching {
|
|
49
49
|
this.watchOptions = {};
|
50
50
|
}
|
51
51
|
if (typeof this.watchOptions.aggregateTimeout !== "number") {
|
52
|
-
this.watchOptions.aggregateTimeout =
|
52
|
+
this.watchOptions.aggregateTimeout = 20;
|
53
53
|
}
|
54
54
|
this.compiler = compiler;
|
55
55
|
this.running = false;
|
@@ -109,30 +109,44 @@ class Watching {
|
|
109
109
|
this.lastWatcherStartTime = Date.now();
|
110
110
|
}
|
111
111
|
this.compiler.fsStartTime = Date.now();
|
112
|
-
|
113
|
-
changedFiles
|
114
|
-
|
112
|
+
if (
|
113
|
+
changedFiles &&
|
114
|
+
removedFiles &&
|
115
|
+
fileTimeInfoEntries &&
|
116
|
+
contextTimeInfoEntries
|
117
|
+
) {
|
118
|
+
this._mergeWithCollected(changedFiles, removedFiles);
|
119
|
+
this.compiler.fileTimestamps = fileTimeInfoEntries;
|
120
|
+
this.compiler.contextTimestamps = contextTimeInfoEntries;
|
121
|
+
} else if (this.pausedWatcher) {
|
122
|
+
if (this.pausedWatcher.getInfo) {
|
123
|
+
const {
|
124
|
+
changes,
|
125
|
+
removals,
|
126
|
+
fileTimeInfoEntries,
|
127
|
+
contextTimeInfoEntries
|
128
|
+
} = this.pausedWatcher.getInfo();
|
129
|
+
this._mergeWithCollected(changes, removals);
|
130
|
+
this.compiler.fileTimestamps = fileTimeInfoEntries;
|
131
|
+
this.compiler.contextTimestamps = contextTimeInfoEntries;
|
132
|
+
} else {
|
133
|
+
this._mergeWithCollected(
|
115
134
|
this.pausedWatcher.getAggregatedChanges &&
|
116
|
-
|
117
|
-
(this.compiler.removedFiles =
|
118
|
-
removedFiles ||
|
119
|
-
(this.pausedWatcher &&
|
135
|
+
this.pausedWatcher.getAggregatedChanges(),
|
120
136
|
this.pausedWatcher.getAggregatedRemovals &&
|
121
|
-
|
122
|
-
|
123
|
-
|
137
|
+
this.pausedWatcher.getAggregatedRemovals()
|
138
|
+
);
|
139
|
+
this.compiler.fileTimestamps =
|
140
|
+
this.pausedWatcher.getFileTimeInfoEntries();
|
141
|
+
this.compiler.contextTimestamps =
|
142
|
+
this.pausedWatcher.getContextTimeInfoEntries();
|
143
|
+
}
|
144
|
+
}
|
124
145
|
this.compiler.modifiedFiles = this._collectedChangedFiles;
|
125
146
|
this._collectedChangedFiles = undefined;
|
126
147
|
this.compiler.removedFiles = this._collectedRemovedFiles;
|
127
148
|
this._collectedRemovedFiles = undefined;
|
128
149
|
|
129
|
-
this.compiler.fileTimestamps =
|
130
|
-
fileTimeInfoEntries ||
|
131
|
-
(this.pausedWatcher && this.pausedWatcher.getFileTimeInfoEntries());
|
132
|
-
this.compiler.contextTimestamps =
|
133
|
-
contextTimeInfoEntries ||
|
134
|
-
(this.pausedWatcher && this.pausedWatcher.getContextTimeInfoEntries());
|
135
|
-
|
136
150
|
const run = () => {
|
137
151
|
if (this.compiler.idle) {
|
138
152
|
return this.compiler.cache.endIdle(err => {
|
@@ -118,11 +118,47 @@ class WebpackOptionsApply extends OptionsApply {
|
|
118
118
|
if (options.externalsPresets.webAsync) {
|
119
119
|
//@ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
|
120
120
|
const ExternalsPlugin = require("./ExternalsPlugin");
|
121
|
-
new ExternalsPlugin(
|
121
|
+
new ExternalsPlugin(
|
122
|
+
"import",
|
123
|
+
options.experiments.css
|
124
|
+
? ({ request, dependencyType }, callback) => {
|
125
|
+
if (dependencyType === "url") {
|
126
|
+
if (/^(\/\/|https?:\/\/)/.test(request))
|
127
|
+
return callback(null, `asset ${request}`);
|
128
|
+
} else if (dependencyType === "css-import") {
|
129
|
+
if (/^(\/\/|https?:\/\/)/.test(request))
|
130
|
+
return callback(null, `css-import ${request}`);
|
131
|
+
} else if (/^(\/\/|https?:\/\/|std:)/.test(request)) {
|
132
|
+
if (/^\.css(\?|$)/.test(request))
|
133
|
+
return callback(null, `css-import ${request}`);
|
134
|
+
return callback(null, `import ${request}`);
|
135
|
+
}
|
136
|
+
callback();
|
137
|
+
}
|
138
|
+
: /^(\/\/|https?:\/\/|std:)/
|
139
|
+
).apply(compiler);
|
122
140
|
} else if (options.externalsPresets.web) {
|
123
141
|
//@ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
|
124
142
|
const ExternalsPlugin = require("./ExternalsPlugin");
|
125
|
-
new ExternalsPlugin(
|
143
|
+
new ExternalsPlugin(
|
144
|
+
"module",
|
145
|
+
options.experiments.css
|
146
|
+
? ({ request, dependencyType }, callback) => {
|
147
|
+
if (dependencyType === "url") {
|
148
|
+
if (/^(\/\/|https?:\/\/)/.test(request))
|
149
|
+
return callback(null, `asset ${request}`);
|
150
|
+
} else if (dependencyType === "css-import") {
|
151
|
+
if (/^(\/\/|https?:\/\/)/.test(request))
|
152
|
+
return callback(null, `css-import ${request}`);
|
153
|
+
} else if (/^(\/\/|https?:\/\/|std:)/.test(request)) {
|
154
|
+
if (/^\.css(\?|$)/.test(request))
|
155
|
+
return callback(null, `css-import ${request}`);
|
156
|
+
return callback(null, `module ${request}`);
|
157
|
+
}
|
158
|
+
callback();
|
159
|
+
}
|
160
|
+
: /^(\/\/|https?:\/\/|std:)/
|
161
|
+
).apply(compiler);
|
126
162
|
}
|
127
163
|
|
128
164
|
new ChunkPrefetchPreloadPlugin().apply(compiler);
|
@@ -253,6 +289,11 @@ class WebpackOptionsApply extends OptionsApply {
|
|
253
289
|
}).apply(compiler);
|
254
290
|
}
|
255
291
|
|
292
|
+
if (options.experiments.css) {
|
293
|
+
const CssModulesPlugin = require("./css/CssModulesPlugin");
|
294
|
+
new CssModulesPlugin().apply(compiler);
|
295
|
+
}
|
296
|
+
|
256
297
|
if (options.experiments.lazyCompilation) {
|
257
298
|
const LazyCompilationPlugin = require("./hmr/LazyCompilationPlugin");
|
258
299
|
const lazyOptions =
|
@@ -49,7 +49,7 @@ const mergeAssetInfo = (a, b) => {
|
|
49
49
|
case "immutable":
|
50
50
|
case "development":
|
51
51
|
case "hotModuleReplacement":
|
52
|
-
case "javascriptModule
|
52
|
+
case "javascriptModule":
|
53
53
|
result[key] = a[key] || b[key];
|
54
54
|
break;
|
55
55
|
case "related":
|
@@ -191,6 +191,8 @@ class AssetGenerator extends Generator {
|
|
191
191
|
encoding ? `;${encoding}` : ""
|
192
192
|
},${encodedContent}`;
|
193
193
|
}
|
194
|
+
const data = getData();
|
195
|
+
data.set("url", encodedSource);
|
194
196
|
return new RawSource(
|
195
197
|
`${RuntimeGlobals.module}.exports = ${JSON.stringify(
|
196
198
|
encodedSource
|
@@ -228,7 +230,7 @@ class AssetGenerator extends Generator {
|
|
228
230
|
contentHash
|
229
231
|
}
|
230
232
|
);
|
231
|
-
let
|
233
|
+
let assetPath;
|
232
234
|
if (this.publicPath !== undefined) {
|
233
235
|
const { path, info } =
|
234
236
|
runtimeTemplate.compilation.getAssetPathWithInfo(
|
@@ -241,11 +243,14 @@ class AssetGenerator extends Generator {
|
|
241
243
|
contentHash
|
242
244
|
}
|
243
245
|
);
|
244
|
-
publicPath = JSON.stringify(path);
|
245
246
|
assetInfo = mergeAssetInfo(assetInfo, info);
|
247
|
+
assetPath = JSON.stringify(path + filename);
|
246
248
|
} else {
|
247
|
-
publicPath = RuntimeGlobals.publicPath;
|
248
249
|
runtimeRequirements.add(RuntimeGlobals.publicPath); // add __webpack_require__.p
|
250
|
+
assetPath = runtimeTemplate.concatenation(
|
251
|
+
{ expr: RuntimeGlobals.publicPath },
|
252
|
+
filename
|
253
|
+
);
|
249
254
|
}
|
250
255
|
assetInfo = {
|
251
256
|
sourceFilename,
|
@@ -264,9 +269,7 @@ class AssetGenerator extends Generator {
|
|
264
269
|
}
|
265
270
|
|
266
271
|
return new RawSource(
|
267
|
-
`${
|
268
|
-
RuntimeGlobals.module
|
269
|
-
}.exports = ${publicPath} + ${JSON.stringify(filename)};`
|
272
|
+
`${RuntimeGlobals.module}.exports = ${assetPath};`
|
270
273
|
);
|
271
274
|
}
|
272
275
|
}
|
@@ -0,0 +1,145 @@
|
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Tobias Koppers @sokra
|
4
|
+
*/
|
5
|
+
|
6
|
+
"use strict";
|
7
|
+
|
8
|
+
const { RawSource } = require("webpack-sources");
|
9
|
+
const Module = require("../Module");
|
10
|
+
const RuntimeGlobals = require("../RuntimeGlobals");
|
11
|
+
const makeSerializable = require("../util/makeSerializable");
|
12
|
+
|
13
|
+
/** @typedef {import("../../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptions */
|
14
|
+
/** @typedef {import("../Compilation")} Compilation */
|
15
|
+
/** @typedef {import("../Dependency").UpdateHashContext} UpdateHashContext */
|
16
|
+
/** @typedef {import("../Module").CodeGenerationContext} CodeGenerationContext */
|
17
|
+
/** @typedef {import("../Module").CodeGenerationResult} CodeGenerationResult */
|
18
|
+
/** @typedef {import("../Module").NeedBuildContext} NeedBuildContext */
|
19
|
+
/** @typedef {import("../RequestShortener")} RequestShortener */
|
20
|
+
/** @typedef {import("../ResolverFactory").ResolverWithOptions} ResolverWithOptions */
|
21
|
+
/** @typedef {import("../WebpackError")} WebpackError */
|
22
|
+
/** @typedef {import("../util/Hash")} Hash */
|
23
|
+
/** @typedef {import("../util/fs").InputFileSystem} InputFileSystem */
|
24
|
+
|
25
|
+
const TYPES = new Set(["javascript"]);
|
26
|
+
|
27
|
+
class RawDataUrlModule extends Module {
|
28
|
+
/**
|
29
|
+
* @param {string} url raw url
|
30
|
+
* @param {string} identifier unique identifier
|
31
|
+
* @param {string=} readableIdentifier readable identifier
|
32
|
+
*/
|
33
|
+
constructor(url, identifier, readableIdentifier) {
|
34
|
+
super("asset/raw-data-url", null);
|
35
|
+
this.url = url;
|
36
|
+
this.identifierStr = identifier || this.url;
|
37
|
+
this.readableIdentifierStr = readableIdentifier || this.identifierStr;
|
38
|
+
}
|
39
|
+
|
40
|
+
/**
|
41
|
+
* @returns {Set<string>} types available (do not mutate)
|
42
|
+
*/
|
43
|
+
getSourceTypes() {
|
44
|
+
return TYPES;
|
45
|
+
}
|
46
|
+
|
47
|
+
/**
|
48
|
+
* @returns {string} a unique identifier of the module
|
49
|
+
*/
|
50
|
+
identifier() {
|
51
|
+
return this.identifierStr;
|
52
|
+
}
|
53
|
+
|
54
|
+
/**
|
55
|
+
* @param {string=} type the source type for which the size should be estimated
|
56
|
+
* @returns {number} the estimated size of the module (must be non-zero)
|
57
|
+
*/
|
58
|
+
size(type) {
|
59
|
+
return Math.max(1, this.url.length);
|
60
|
+
}
|
61
|
+
|
62
|
+
/**
|
63
|
+
* @param {RequestShortener} requestShortener the request shortener
|
64
|
+
* @returns {string} a user readable identifier of the module
|
65
|
+
*/
|
66
|
+
readableIdentifier(requestShortener) {
|
67
|
+
return requestShortener.shorten(this.readableIdentifierStr);
|
68
|
+
}
|
69
|
+
|
70
|
+
/**
|
71
|
+
* @param {NeedBuildContext} context context info
|
72
|
+
* @param {function(WebpackError=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
|
73
|
+
* @returns {void}
|
74
|
+
*/
|
75
|
+
needBuild(context, callback) {
|
76
|
+
return callback(null, !this.buildMeta);
|
77
|
+
}
|
78
|
+
|
79
|
+
/**
|
80
|
+
* @param {WebpackOptions} options webpack options
|
81
|
+
* @param {Compilation} compilation the compilation
|
82
|
+
* @param {ResolverWithOptions} resolver the resolver
|
83
|
+
* @param {InputFileSystem} fs the file system
|
84
|
+
* @param {function(WebpackError=): void} callback callback function
|
85
|
+
* @returns {void}
|
86
|
+
*/
|
87
|
+
build(options, compilation, resolver, fs, callback) {
|
88
|
+
this.buildMeta = {};
|
89
|
+
this.buildInfo = {
|
90
|
+
cacheable: true
|
91
|
+
};
|
92
|
+
callback();
|
93
|
+
}
|
94
|
+
|
95
|
+
/**
|
96
|
+
* @param {CodeGenerationContext} context context for code generation
|
97
|
+
* @returns {CodeGenerationResult} result
|
98
|
+
*/
|
99
|
+
codeGeneration(context) {
|
100
|
+
const sources = new Map();
|
101
|
+
sources.set(
|
102
|
+
"javascript",
|
103
|
+
new RawSource(`module.exports = ${JSON.stringify(this.url)};`)
|
104
|
+
);
|
105
|
+
const data = new Map();
|
106
|
+
data.set("url", this.url);
|
107
|
+
const runtimeRequirements = new Set();
|
108
|
+
runtimeRequirements.add(RuntimeGlobals.module);
|
109
|
+
return { sources, runtimeRequirements, data };
|
110
|
+
}
|
111
|
+
|
112
|
+
/**
|
113
|
+
* @param {Hash} hash the hash used to track dependencies
|
114
|
+
* @param {UpdateHashContext} context context
|
115
|
+
* @returns {void}
|
116
|
+
*/
|
117
|
+
updateHash(hash, context) {
|
118
|
+
hash.update(this.url);
|
119
|
+
super.updateHash(hash, context);
|
120
|
+
}
|
121
|
+
|
122
|
+
serialize(context) {
|
123
|
+
const { write } = context;
|
124
|
+
|
125
|
+
write(this.url);
|
126
|
+
write(this.identifierStr);
|
127
|
+
write(this.readableIdentifierStr);
|
128
|
+
|
129
|
+
super.serialize(context);
|
130
|
+
}
|
131
|
+
|
132
|
+
deserialize(context) {
|
133
|
+
const { read } = context;
|
134
|
+
|
135
|
+
this.url = read();
|
136
|
+
this.identifierStr = read();
|
137
|
+
this.readableIdentifierStr = read();
|
138
|
+
|
139
|
+
super.deserialize(context);
|
140
|
+
}
|
141
|
+
}
|
142
|
+
|
143
|
+
makeSerializable(RawDataUrlModule, "webpack/lib/asset/RawDataUrlModule");
|
144
|
+
|
145
|
+
module.exports = RawDataUrlModule;
|
@@ -274,7 +274,44 @@ const resolve = browsers => {
|
|
274
274
|
// kaios: Unknown support
|
275
275
|
node: [12, 0]
|
276
276
|
}),
|
277
|
-
|
277
|
+
optionalChaining: rawChecker({
|
278
|
+
chrome: 80,
|
279
|
+
and_chr: 80,
|
280
|
+
edge: 80,
|
281
|
+
firefox: 74,
|
282
|
+
and_ff: 79,
|
283
|
+
// ie: Not supported,
|
284
|
+
opera: 67,
|
285
|
+
op_mob: 64,
|
286
|
+
safari: [13, 1],
|
287
|
+
ios_saf: [13, 4],
|
288
|
+
samsung: 13,
|
289
|
+
android: 80,
|
290
|
+
// and_qq: Not supported
|
291
|
+
// baidu: Not supported
|
292
|
+
// and_uc: Not supported
|
293
|
+
// kaios: Not supported
|
294
|
+
node: 14
|
295
|
+
}),
|
296
|
+
templateLiteral: rawChecker({
|
297
|
+
chrome: 41,
|
298
|
+
and_chr: 41,
|
299
|
+
edge: 13,
|
300
|
+
firefox: 34,
|
301
|
+
and_ff: 34,
|
302
|
+
// ie: Not supported,
|
303
|
+
opera: 29,
|
304
|
+
op_mob: 64,
|
305
|
+
safari: [9, 1],
|
306
|
+
ios_saf: 9,
|
307
|
+
samsung: 4,
|
308
|
+
android: 41,
|
309
|
+
and_qq: [10, 4],
|
310
|
+
baidu: [7, 12],
|
311
|
+
and_uc: [12, 12],
|
312
|
+
kaios: [2, 5],
|
313
|
+
node: 4
|
314
|
+
}),
|
278
315
|
browser: browserProperty,
|
279
316
|
electron: false,
|
280
317
|
node: nodeProperty,
|