webpack 5.39.1 → 5.40.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of webpack might be problematic. Click here for more details.
- package/README.md +10 -10
- package/lib/cache/PackFileCacheStrategy.js +1 -1
- package/lib/cli.js +1 -1
- package/lib/javascript/JavascriptParser.js +10 -3
- package/lib/node/NodeTargetPlugin.js +1 -0
- package/lib/optimize/InnerGraphPlugin.js +33 -2
- package/lib/serialization/PlainObjectSerializer.js +17 -8
- package/lib/serialization/Serializer.js +2 -2
- package/lib/serialization/SerializerMiddleware.js +7 -4
- package/lib/util/LazySet.js +26 -17
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +2 -2
- package/package.json +4 -4
- package/types.d.ts +15 -11
package/README.md
CHANGED
@@ -40,7 +40,7 @@
|
|
40
40
|
</a>
|
41
41
|
<h1>webpack</h1>
|
42
42
|
<p>
|
43
|
-
|
43
|
+
Webpack is a module bundler. Its main purpose is to bundle JavaScript files for usage in a browser, yet it is also capable of transforming, bundling, or packaging just about any resource or asset.
|
44
44
|
</p>
|
45
45
|
</div>
|
46
46
|
|
@@ -77,7 +77,7 @@ yarn add webpack --dev
|
|
77
77
|
|
78
78
|
<h2 align="center">Introduction</h2>
|
79
79
|
|
80
|
-
|
80
|
+
Webpack is a bundler for modules. The main purpose is to bundle JavaScript
|
81
81
|
files for usage in a browser, yet it is also capable of transforming, bundling,
|
82
82
|
or packaging just about any resource or asset.
|
83
83
|
|
@@ -95,14 +95,14 @@ Check out webpack's quick [**Get Started**](https://webpack.js.org/guides/gettin
|
|
95
95
|
|
96
96
|
### Browser Compatibility
|
97
97
|
|
98
|
-
|
99
|
-
|
98
|
+
Webpack supports all browsers that are [ES5-compliant](https://kangax.github.io/compat-table/es5/) (IE8 and below are not supported).
|
99
|
+
Webpack also needs `Promise` for `import()` and `require.ensure()`. If you want to support older browsers, you will need to [load a polyfill](https://webpack.js.org/guides/shimming/) before using these expressions.
|
100
100
|
|
101
101
|
<h2 align="center">Concepts</h2>
|
102
102
|
|
103
103
|
### [Plugins](https://webpack.js.org/plugins/)
|
104
104
|
|
105
|
-
|
105
|
+
Webpack has a [rich plugin
|
106
106
|
interface](https://webpack.js.org/plugins/). Most of the features
|
107
107
|
within webpack itself use this plugin interface. This makes webpack very
|
108
108
|
**flexible**.
|
@@ -129,7 +129,7 @@ within webpack itself use this plugin interface. This makes webpack very
|
|
129
129
|
|
130
130
|
### [Loaders](https://webpack.js.org/loaders/)
|
131
131
|
|
132
|
-
|
132
|
+
Webpack enables the use of loaders to preprocess files. This allows you to bundle
|
133
133
|
**any static resource** way beyond JavaScript. You can easily [write your own
|
134
134
|
loaders](https://webpack.js.org/api/loaders/) using Node.js.
|
135
135
|
|
@@ -249,23 +249,23 @@ or are automatically applied via regex from your webpack configuration.
|
|
249
249
|
|
250
250
|
### Performance
|
251
251
|
|
252
|
-
|
252
|
+
Webpack uses async I/O and has multiple caching levels. This makes webpack fast
|
253
253
|
and incredibly **fast** on incremental compilations.
|
254
254
|
|
255
255
|
### Module Formats
|
256
256
|
|
257
|
-
|
257
|
+
Webpack supports ES2015+, CommonJS and AMD modules **out of the box**. It performs clever static
|
258
258
|
analysis on the AST of your code. It even has an evaluation engine to evaluate
|
259
259
|
simple expressions. This allows you to **support most existing libraries** out of the box.
|
260
260
|
|
261
261
|
### [Code Splitting](https://webpack.js.org/guides/code-splitting/)
|
262
262
|
|
263
|
-
|
263
|
+
Webpack allows you to split your codebase into multiple chunks. Chunks are
|
264
264
|
loaded asynchronously at runtime. This reduces the initial loading time.
|
265
265
|
|
266
266
|
### [Optimizations](https://webpack.js.org/guides/production-build/)
|
267
267
|
|
268
|
-
|
268
|
+
Webpack can do many optimizations to **reduce the output size of your
|
269
269
|
JavaScript** by deduplicating frequently used modules, minifying, and giving
|
270
270
|
you full control of what is loaded initially and what is loaded at runtime
|
271
271
|
through code splitting. It can also make your code chunks **cache
|
@@ -678,7 +678,7 @@ class PackContent {
|
|
678
678
|
*/
|
679
679
|
constructor(items, usedItems, dataOrFn, logger, lazyName) {
|
680
680
|
this.items = items;
|
681
|
-
/** @type {function(): PackContentItems |
|
681
|
+
/** @type {function(): Promise<PackContentItems> | PackContentItems } */
|
682
682
|
this.lazy = typeof dataOrFn === "function" ? dataOrFn : undefined;
|
683
683
|
/** @type {Map<string, any>} */
|
684
684
|
this.content = typeof dataOrFn === "function" ? undefined : dataOrFn.map;
|
package/lib/cli.js
CHANGED
@@ -148,7 +148,7 @@ const getArguments = (schema = webpackSchema) => {
|
|
148
148
|
{
|
149
149
|
type: "reset",
|
150
150
|
multiple: false,
|
151
|
-
description: `Clear all items provided in configuration. ${description}`,
|
151
|
+
description: `Clear all items provided in '${schemaPath}' configuration. ${description}`,
|
152
152
|
path: schemaPath
|
153
153
|
}
|
154
154
|
],
|
@@ -175,11 +175,18 @@ class JavascriptParser extends Parser {
|
|
175
175
|
/** @type {SyncBailHook<[IfStatementNode], boolean | void>} */
|
176
176
|
statementIf: new SyncBailHook(["statement"]),
|
177
177
|
/** @type {SyncBailHook<[ExpressionNode, ClassExpressionNode | ClassDeclarationNode], boolean | void>} */
|
178
|
-
classExtendsExpression: new SyncBailHook([
|
178
|
+
classExtendsExpression: new SyncBailHook([
|
179
|
+
"expression",
|
180
|
+
"classDefinition"
|
181
|
+
]),
|
179
182
|
/** @type {SyncBailHook<[MethodDefinitionNode | PropertyDefinitionNode, ClassExpressionNode | ClassDeclarationNode], boolean | void>} */
|
180
|
-
classBodyElement: new SyncBailHook(["element", "
|
183
|
+
classBodyElement: new SyncBailHook(["element", "classDefinition"]),
|
181
184
|
/** @type {SyncBailHook<[ExpressionNode, MethodDefinitionNode | PropertyDefinitionNode, ClassExpressionNode | ClassDeclarationNode], boolean | void>} */
|
182
|
-
classBodyValue: new SyncBailHook([
|
185
|
+
classBodyValue: new SyncBailHook([
|
186
|
+
"expression",
|
187
|
+
"element",
|
188
|
+
"classDefinition"
|
189
|
+
]),
|
183
190
|
/** @type {HookMap<SyncBailHook<[LabeledStatementNode], boolean | void>>} */
|
184
191
|
label: new HookMap(() => new SyncBailHook(["statement"])),
|
185
192
|
/** @type {SyncBailHook<[StatementNode, ImportSource], boolean | void>} */
|
@@ -238,12 +238,25 @@ class InnerGraphPlugin {
|
|
238
238
|
}
|
239
239
|
);
|
240
240
|
|
241
|
+
parser.hooks.classBodyElement.tap(
|
242
|
+
"InnerGraphPlugin",
|
243
|
+
(element, classDefinition) => {
|
244
|
+
if (!InnerGraph.isEnabled(parser.state)) return;
|
245
|
+
if (parser.scope.topLevelScope === true) {
|
246
|
+
const fn = classWithTopLevelSymbol.get(classDefinition);
|
247
|
+
if (fn) {
|
248
|
+
InnerGraph.setTopLevelSymbol(parser.state, undefined);
|
249
|
+
}
|
250
|
+
}
|
251
|
+
}
|
252
|
+
);
|
253
|
+
|
241
254
|
parser.hooks.classBodyValue.tap(
|
242
255
|
"InnerGraphPlugin",
|
243
|
-
(expression, element,
|
256
|
+
(expression, element, classDefinition) => {
|
244
257
|
if (!InnerGraph.isEnabled(parser.state)) return;
|
245
258
|
if (parser.scope.topLevelScope === true) {
|
246
|
-
const fn = classWithTopLevelSymbol.get(
|
259
|
+
const fn = classWithTopLevelSymbol.get(classDefinition);
|
247
260
|
if (fn) {
|
248
261
|
if (
|
249
262
|
!element.static ||
|
@@ -253,6 +266,24 @@ class InnerGraphPlugin {
|
|
253
266
|
)
|
254
267
|
) {
|
255
268
|
InnerGraph.setTopLevelSymbol(parser.state, fn);
|
269
|
+
if (element.type !== "MethodDefinition" && element.static) {
|
270
|
+
InnerGraph.onUsage(parser.state, usedByExports => {
|
271
|
+
switch (usedByExports) {
|
272
|
+
case undefined:
|
273
|
+
case true:
|
274
|
+
return;
|
275
|
+
default: {
|
276
|
+
const dep = new PureExpressionDependency(
|
277
|
+
expression.range
|
278
|
+
);
|
279
|
+
dep.loc = expression.loc;
|
280
|
+
dep.usedByExports = usedByExports;
|
281
|
+
parser.state.module.addDependency(dep);
|
282
|
+
break;
|
283
|
+
}
|
284
|
+
}
|
285
|
+
});
|
286
|
+
}
|
256
287
|
} else {
|
257
288
|
InnerGraph.setTopLevelSymbol(parser.state, undefined);
|
258
289
|
}
|
@@ -7,19 +7,21 @@
|
|
7
7
|
const cache = new WeakMap();
|
8
8
|
|
9
9
|
class ObjectStructure {
|
10
|
-
constructor(
|
11
|
-
this.keys =
|
12
|
-
this.children =
|
10
|
+
constructor() {
|
11
|
+
this.keys = undefined;
|
12
|
+
this.children = undefined;
|
13
13
|
}
|
14
14
|
|
15
|
-
getKeys() {
|
15
|
+
getKeys(keys) {
|
16
|
+
if (this.keys === undefined) this.keys = keys;
|
16
17
|
return this.keys;
|
17
18
|
}
|
18
19
|
|
19
20
|
key(key) {
|
21
|
+
if (this.children === undefined) this.children = new Map();
|
20
22
|
const child = this.children.get(key);
|
21
23
|
if (child !== undefined) return child;
|
22
|
-
const newChild = new ObjectStructure(
|
24
|
+
const newChild = new ObjectStructure();
|
23
25
|
this.children.set(key, newChild);
|
24
26
|
return newChild;
|
25
27
|
}
|
@@ -28,20 +30,27 @@ class ObjectStructure {
|
|
28
30
|
const getCachedKeys = (keys, cacheAssoc) => {
|
29
31
|
let root = cache.get(cacheAssoc);
|
30
32
|
if (root === undefined) {
|
31
|
-
root = new ObjectStructure(
|
33
|
+
root = new ObjectStructure();
|
32
34
|
cache.set(cacheAssoc, root);
|
33
35
|
}
|
34
36
|
let current = root;
|
35
37
|
for (const key of keys) {
|
36
38
|
current = current.key(key);
|
37
39
|
}
|
38
|
-
return current.getKeys();
|
40
|
+
return current.getKeys(keys);
|
39
41
|
};
|
40
42
|
|
41
43
|
class PlainObjectSerializer {
|
42
44
|
serialize(obj, { write }) {
|
43
45
|
const keys = Object.keys(obj);
|
44
|
-
if (keys.length >
|
46
|
+
if (keys.length > 128) {
|
47
|
+
// Objects with so many keys are unlikely to share structure
|
48
|
+
// with other objects
|
49
|
+
write(keys);
|
50
|
+
for (const key of keys) {
|
51
|
+
write(obj[key]);
|
52
|
+
}
|
53
|
+
} else if (keys.length > 1) {
|
45
54
|
write(getCachedKeys(keys, write));
|
46
55
|
for (const key of keys) {
|
47
56
|
write(obj[key]);
|
@@ -15,7 +15,7 @@ class Serializer {
|
|
15
15
|
const ctx = { ...context, ...this.context };
|
16
16
|
let current = obj;
|
17
17
|
for (const middleware of this.serializeMiddlewares) {
|
18
|
-
if (current
|
18
|
+
if (current && typeof current.then === "function") {
|
19
19
|
current = current.then(
|
20
20
|
data => data && middleware.serialize(data, context)
|
21
21
|
);
|
@@ -35,7 +35,7 @@ class Serializer {
|
|
35
35
|
/** @type {any} */
|
36
36
|
let current = value;
|
37
37
|
for (const middleware of this.deserializeMiddlewares) {
|
38
|
-
if (current
|
38
|
+
if (current && typeof current.then === "function") {
|
39
39
|
current = current.then(data => middleware.deserialize(data, context));
|
40
40
|
} else {
|
41
41
|
current = middleware.deserialize(current, ctx);
|
@@ -100,9 +100,10 @@ class SerializerMiddleware {
|
|
100
100
|
static serializeLazy(lazy, serialize) {
|
101
101
|
const fn = memoize(() => {
|
102
102
|
const r = lazy();
|
103
|
-
if (r
|
104
|
-
|
105
|
-
|
103
|
+
if (r && typeof r.then === "function") {
|
104
|
+
return r.then(data => data && serialize(data));
|
105
|
+
}
|
106
|
+
return serialize(r);
|
106
107
|
});
|
107
108
|
fn[LAZY_TARGET] = lazy[LAZY_TARGET];
|
108
109
|
/** @type {any} */ (fn).options = /** @type {any} */ (lazy).options;
|
@@ -118,7 +119,9 @@ class SerializerMiddleware {
|
|
118
119
|
static deserializeLazy(lazy, deserialize) {
|
119
120
|
const fn = memoize(() => {
|
120
121
|
const r = lazy();
|
121
|
-
if (r
|
122
|
+
if (r && typeof r.then === "function") {
|
123
|
+
return r.then(data => deserialize(data));
|
124
|
+
}
|
122
125
|
return deserialize(r);
|
123
126
|
});
|
124
127
|
fn[LAZY_TARGET] = lazy[LAZY_TARGET];
|
package/lib/util/LazySet.js
CHANGED
@@ -24,21 +24,17 @@ const merge = (targetSet, toMerge) => {
|
|
24
24
|
/**
|
25
25
|
* @template T
|
26
26
|
* @param {Set<Iterable<T>>} targetSet set where iterables should be added
|
27
|
-
* @param {Array<
|
27
|
+
* @param {Array<LazySet<T>>} toDeepMerge lazy sets to be flattened
|
28
28
|
* @returns {void}
|
29
29
|
*/
|
30
30
|
const flatten = (targetSet, toDeepMerge) => {
|
31
31
|
for (const set of toDeepMerge) {
|
32
|
-
if (set
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
targetSet.add(mergedSet);
|
37
|
-
}
|
38
|
-
flatten(targetSet, set._toDeepMerge);
|
32
|
+
if (set._set.size > 0) targetSet.add(set._set);
|
33
|
+
if (set._needMerge) {
|
34
|
+
for (const mergedSet of set._toMerge) {
|
35
|
+
targetSet.add(mergedSet);
|
39
36
|
}
|
40
|
-
|
41
|
-
targetSet.add(set);
|
37
|
+
flatten(targetSet, set._toDeepMerge);
|
42
38
|
}
|
43
39
|
}
|
44
40
|
};
|
@@ -58,7 +54,7 @@ class LazySet {
|
|
58
54
|
this._set = new Set(iterable);
|
59
55
|
/** @type {Set<Iterable<T>>} */
|
60
56
|
this._toMerge = new Set();
|
61
|
-
/** @type {Array<
|
57
|
+
/** @type {Array<LazySet<T>>} */
|
62
58
|
this._toDeepMerge = [];
|
63
59
|
this._needMerge = false;
|
64
60
|
this._deopt = false;
|
@@ -76,6 +72,14 @@ class LazySet {
|
|
76
72
|
this._needMerge = false;
|
77
73
|
}
|
78
74
|
|
75
|
+
_isEmpty() {
|
76
|
+
return (
|
77
|
+
this._set.size === 0 &&
|
78
|
+
this._toMerge.size === 0 &&
|
79
|
+
this._toDeepMerge.length === 0
|
80
|
+
);
|
81
|
+
}
|
82
|
+
|
79
83
|
get size() {
|
80
84
|
if (this._needMerge) this._merge();
|
81
85
|
return this._set.size;
|
@@ -101,13 +105,18 @@ class LazySet {
|
|
101
105
|
_set.add(item);
|
102
106
|
}
|
103
107
|
} else {
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
this.
|
109
|
-
|
108
|
+
if (iterable instanceof LazySet) {
|
109
|
+
if (iterable._isEmpty()) return this;
|
110
|
+
this._toDeepMerge.push(iterable);
|
111
|
+
this._needMerge = true;
|
112
|
+
if (this._toDeepMerge.length > 100000) {
|
113
|
+
this._flatten();
|
114
|
+
}
|
115
|
+
} else {
|
116
|
+
this._toMerge.add(iterable);
|
117
|
+
this._needMerge = true;
|
110
118
|
}
|
119
|
+
if (this._toMerge.size > 100000) this._merge();
|
111
120
|
}
|
112
121
|
return this;
|
113
122
|
}
|
@@ -291,7 +291,7 @@ class WasmChunkLoadingRuntimeModule extends RuntimeModule {
|
|
291
291
|
"var promise;",
|
292
292
|
this.supportsStreaming
|
293
293
|
? Template.asString([
|
294
|
-
"if(importObject
|
294
|
+
"if(importObject && typeof importObject.then === 'function' && typeof WebAssembly.compileStreaming === 'function') {",
|
295
295
|
Template.indent([
|
296
296
|
"promise = Promise.all([WebAssembly.compileStreaming(req), importObject]).then(function(items) {",
|
297
297
|
Template.indent([
|
@@ -309,7 +309,7 @@ class WasmChunkLoadingRuntimeModule extends RuntimeModule {
|
|
309
309
|
])
|
310
310
|
])
|
311
311
|
: Template.asString([
|
312
|
-
"if(importObject
|
312
|
+
"if(importObject && typeof importObject.then === 'function') {",
|
313
313
|
Template.indent([
|
314
314
|
"var bytesPromise = req.then(function(x) { return x.arrayBuffer(); });",
|
315
315
|
"promise = Promise.all([",
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "webpack",
|
3
|
-
"version": "5.
|
3
|
+
"version": "5.40.0",
|
4
4
|
"author": "Tobias Koppers @sokra",
|
5
5
|
"description": "Packs CommonJs/AMD modules for the browser. Allows to split your codebase into multiple bundles, which can be loaded on demand. Support loaders to preprocess files, i.e. json, jsx, es7, css, less, ... and your custom stuff.",
|
6
6
|
"license": "MIT",
|
@@ -14,7 +14,7 @@
|
|
14
14
|
"browserslist": "^4.14.5",
|
15
15
|
"chrome-trace-event": "^1.0.2",
|
16
16
|
"enhanced-resolve": "^5.8.0",
|
17
|
-
"es-module-lexer": "^0.
|
17
|
+
"es-module-lexer": "^0.6.0",
|
18
18
|
"eslint-scope": "5.1.1",
|
19
19
|
"events": "^3.2.0",
|
20
20
|
"glob-to-regexp": "^0.4.1",
|
@@ -25,7 +25,7 @@
|
|
25
25
|
"neo-async": "^2.6.2",
|
26
26
|
"schema-utils": "^3.0.0",
|
27
27
|
"tapable": "^2.1.1",
|
28
|
-
"terser-webpack-plugin": "^5.1.
|
28
|
+
"terser-webpack-plugin": "^5.1.3",
|
29
29
|
"watchpack": "^2.2.0",
|
30
30
|
"webpack-sources": "^2.3.0"
|
31
31
|
},
|
@@ -91,7 +91,7 @@
|
|
91
91
|
"simple-git": "^2.17.0",
|
92
92
|
"strip-ansi": "^6.0.0",
|
93
93
|
"style-loader": "^2.0.0",
|
94
|
-
"terser": "^5.
|
94
|
+
"terser": "^5.7.0",
|
95
95
|
"toml": "^3.0.0",
|
96
96
|
"tooling": "webpack/tooling#v1.19.0",
|
97
97
|
"ts-loader": "^8.0.2",
|
package/types.d.ts
CHANGED
@@ -5795,11 +5795,13 @@ type LoaderContext<OptionsType> = NormalModuleLoaderContext<OptionsType> &
|
|
5795
5795
|
LoaderRunnerLoaderContext<OptionsType> &
|
5796
5796
|
LoaderPluginLoaderContext &
|
5797
5797
|
HotModuleReplacementPluginLoaderContext;
|
5798
|
-
type LoaderDefinition<
|
5799
|
-
|
5800
|
-
|
5801
|
-
|
5802
|
-
|
5798
|
+
type LoaderDefinition<
|
5799
|
+
OptionsType = {},
|
5800
|
+
ContextAdditions = {}
|
5801
|
+
> = LoaderDefinitionFunction<OptionsType, ContextAdditions> & {
|
5802
|
+
raw?: false;
|
5803
|
+
pitch?: PitchLoaderDefinitionFunction<OptionsType, ContextAdditions>;
|
5804
|
+
};
|
5803
5805
|
declare interface LoaderDefinitionFunction<
|
5804
5806
|
OptionsType = {},
|
5805
5807
|
ContextAdditions = {}
|
@@ -7204,7 +7206,7 @@ declare interface NormalModuleLoaderContext<OptionsType> {
|
|
7204
7206
|
};
|
7205
7207
|
emitFile(
|
7206
7208
|
name: string,
|
7207
|
-
content: string,
|
7209
|
+
content: string | Buffer,
|
7208
7210
|
sourceMap?: string,
|
7209
7211
|
assetInfo?: AssetInfo
|
7210
7212
|
): void;
|
@@ -8662,11 +8664,13 @@ declare interface RawChunkGroupOptions {
|
|
8662
8664
|
preloadOrder?: number;
|
8663
8665
|
prefetchOrder?: number;
|
8664
8666
|
}
|
8665
|
-
type RawLoaderDefinition<
|
8666
|
-
|
8667
|
-
|
8668
|
-
|
8669
|
-
|
8667
|
+
type RawLoaderDefinition<
|
8668
|
+
OptionsType = {},
|
8669
|
+
ContextAdditions = {}
|
8670
|
+
> = RawLoaderDefinitionFunction<OptionsType, ContextAdditions> & {
|
8671
|
+
raw: true;
|
8672
|
+
pitch?: PitchLoaderDefinitionFunction<OptionsType, ContextAdditions>;
|
8673
|
+
};
|
8670
8674
|
declare interface RawLoaderDefinitionFunction<
|
8671
8675
|
OptionsType = {},
|
8672
8676
|
ContextAdditions = {}
|