webpack 4.1.0 → 4.4.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.
- package/README.md +719 -721
- package/bin/webpack.js +69 -10
- package/lib/APIPlugin.js +84 -84
- package/lib/AmdMainTemplatePlugin.js +75 -77
- package/lib/AsyncDependencyToInitialChunkError.js +21 -23
- package/lib/BannerPlugin.js +101 -101
- package/lib/Chunk.js +477 -469
- package/lib/ChunkTemplate.js +51 -53
- package/lib/Compilation.js +1858 -1851
- package/lib/Compiler.js +493 -478
- package/lib/ConcurrentCompilationError.js +19 -0
- package/lib/ContextModule.js +696 -685
- package/lib/ContextModuleFactory.js +245 -243
- package/lib/DefinePlugin.js +197 -197
- package/lib/DelegatedModule.js +101 -101
- package/lib/DependenciesBlockVariable.js +51 -52
- package/lib/Dependency.js +53 -52
- package/lib/DllModule.js +54 -54
- package/lib/DllModuleFactory.js +29 -29
- package/lib/EnvironmentPlugin.js +65 -67
- package/lib/EvalDevToolModuleTemplatePlugin.js +60 -60
- package/lib/EvalSourceMapDevToolModuleTemplatePlugin.js +105 -105
- package/lib/ExportPropertyMainTemplatePlugin.js +40 -40
- package/lib/ExternalModule.js +159 -159
- package/lib/FunctionModuleTemplatePlugin.js +98 -98
- package/lib/HotModuleReplacement.runtime.js +631 -631
- package/lib/HotModuleReplacementPlugin.js +407 -406
- package/lib/HotUpdateChunkTemplate.js +78 -80
- package/lib/JavascriptGenerator.js +228 -229
- package/lib/JavascriptModulesPlugin.js +184 -158
- package/lib/JsonGenerator.js +42 -42
- package/lib/MainTemplate.js +406 -402
- package/lib/Module.js +343 -340
- package/lib/ModuleBuildError.js +42 -42
- package/lib/ModuleError.js +28 -28
- package/lib/ModuleFilenameHelpers.js +166 -166
- package/lib/ModuleTemplate.js +77 -79
- package/lib/ModuleWarning.js +30 -30
- package/lib/MultiCompiler.js +271 -259
- package/lib/MultiModule.js +78 -75
- package/lib/MultiModuleFactory.js +23 -23
- package/lib/MultiWatching.js +38 -37
- package/lib/NoModeWarning.js +23 -21
- package/lib/NormalModule.js +478 -470
- package/lib/NormalModuleFactory.js +483 -481
- package/lib/OptionsDefaulter.js +80 -86
- package/lib/Parser.js +2074 -2071
- package/lib/ProgressPlugin.js +231 -231
- package/lib/RawModule.js +54 -55
- package/lib/RecordIdsPlugin.js +160 -160
- package/lib/RemovedPluginError.js +13 -13
- package/lib/ResolverFactory.js +64 -67
- package/lib/RuntimeTemplate.js +267 -297
- package/lib/SetVarMainTemplatePlugin.js +57 -57
- package/lib/SourceMapDevToolPlugin.js +302 -308
- package/lib/Stats.js +1234 -1212
- package/lib/Template.js +205 -205
- package/lib/TemplatedPathPlugin.js +170 -143
- package/lib/UmdMainTemplatePlugin.js +264 -269
- package/lib/Watching.js +193 -193
- package/lib/WebAssemblyParser.js +50 -54
- package/lib/WebpackOptionsApply.js +401 -401
- package/lib/WebpackOptionsDefaulter.js +337 -317
- package/lib/WebpackOptionsValidationError.js +316 -319
- package/lib/debug/ProfilingPlugin.js +409 -405
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +328 -311
- package/lib/dependencies/AMDRequireContextDependency.js +20 -20
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +270 -241
- package/lib/dependencies/HarmonyAcceptImportDependency.js +23 -23
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +620 -606
- package/lib/dependencies/HarmonyExportSpecifierDependency.js +53 -53
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +214 -214
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +154 -156
- package/lib/dependencies/ImportDependenciesBlock.js +17 -17
- package/lib/dependencies/ImportDependency.js +34 -34
- package/lib/dependencies/ImportEagerDependency.js +32 -32
- package/lib/dependencies/ImportParserPlugin.js +175 -179
- package/lib/dependencies/ImportWeakDependency.js +34 -34
- package/lib/dependencies/JsonExportsDependency.js +25 -25
- package/lib/dependencies/ModuleDependency.js +20 -20
- package/lib/dependencies/NullDependency.js +20 -20
- package/lib/dependencies/RequireContextDependency.js +22 -22
- package/lib/dependencies/RequireIncludeDependency.js +40 -40
- package/lib/dependencies/WebpackMissingModule.js +20 -22
- package/lib/node/NodeChunkTemplatePlugin.js +31 -31
- package/lib/node/NodeHotUpdateChunkTemplatePlugin.js +36 -36
- package/lib/node/NodeMainTemplatePlugin.js +320 -273
- package/lib/node/ReadFileCompileWasmMainTemplatePlugin.js +113 -115
- package/lib/optimize/AggressiveSplittingPlugin.js +281 -281
- package/lib/optimize/ConcatenatedModule.js +1364 -1366
- package/lib/optimize/RemoveParentModulesPlugin.js +114 -114
- package/lib/optimize/SplitChunksPlugin.js +519 -491
- package/lib/performance/SizeLimitsPlugin.js +105 -105
- package/lib/util/TrackingSet.js +35 -35
- package/lib/util/objectToMap.js +10 -10
- package/lib/wasm/WasmModuleTemplatePlugin.js +106 -106
- package/lib/web/JsonpChunkTemplatePlugin.js +47 -47
- package/lib/web/JsonpExportMainTemplatePlugin.js +47 -47
- package/lib/web/JsonpHotUpdateChunkTemplatePlugin.js +39 -39
- package/lib/web/JsonpMainTemplatePlugin.js +425 -403
- package/lib/webpack.js +182 -179
- package/lib/webworker/WebWorkerChunkTemplatePlugin.js +35 -35
- package/lib/webworker/WebWorkerHotUpdateChunkTemplatePlugin.js +40 -40
- package/lib/webworker/WebWorkerMainTemplatePlugin.js +177 -154
- package/package.json +9 -8
- package/schemas/WebpackOptions.json +1973 -1951
- package/schemas/ajv.absolutePath.js +55 -29
- package/schemas/plugins/BannerPlugin.json +85 -85
- package/schemas/plugins/DllPlugin.json +28 -28
- package/schemas/plugins/DllReferencePlugin.json +99 -99
- package/schemas/plugins/HashedModuleIdsPlugin.json +24 -24
- package/schemas/plugins/LoaderOptionsPlugin.json +26 -26
- package/schemas/plugins/SourceMapDevToolPlugin.json +187 -187
- package/schemas/plugins/WatchIgnorePlugin.json +16 -16
- package/schemas/plugins/debug/ProfilingPlugin.json +12 -12
- package/schemas/plugins/optimize/AggressiveSplittingPlugin.json +22 -22
- package/schemas/plugins/optimize/LimitChunkCountPlugin.json +15 -15
- package/schemas/plugins/optimize/MinChunkSizePlugin.json +13 -13
@@ -1,105 +1,105 @@
|
|
1
|
-
/*
|
2
|
-
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
-
Author Sean Larkin @thelarkinn
|
4
|
-
*/
|
5
|
-
"use strict";
|
6
|
-
const EntrypointsOverSizeLimitWarning = require("./EntrypointsOverSizeLimitWarning");
|
7
|
-
const AssetsOverSizeLimitWarning = require("./AssetsOverSizeLimitWarning");
|
8
|
-
const NoAsyncChunksWarning = require("./NoAsyncChunksWarning");
|
9
|
-
|
10
|
-
module.exports = class SizeLimitsPlugin {
|
11
|
-
constructor(options) {
|
12
|
-
this.hints = options.hints;
|
13
|
-
this.maxAssetSize = options.maxAssetSize;
|
14
|
-
this.maxEntrypointSize = options.maxEntrypointSize;
|
15
|
-
this.assetFilter = options.assetFilter;
|
16
|
-
}
|
17
|
-
apply(compiler) {
|
18
|
-
const entrypointSizeLimit = this.maxEntrypointSize;
|
19
|
-
const assetSizeLimit = this.maxAssetSize;
|
20
|
-
const hints = this.hints;
|
21
|
-
const assetFilter = this.assetFilter || (asset => !asset.endsWith(".map"));
|
22
|
-
|
23
|
-
compiler.hooks.afterEmit.tap("SizeLimitsPlugin", compilation => {
|
24
|
-
const warnings = [];
|
25
|
-
|
26
|
-
const getEntrypointSize = entrypoint =>
|
27
|
-
entrypoint.getFiles().reduce((currentSize, file) => {
|
28
|
-
if (assetFilter(file) && compilation.assets[file]) {
|
29
|
-
return currentSize + compilation.assets[file].size();
|
30
|
-
}
|
31
|
-
|
32
|
-
return currentSize;
|
33
|
-
}, 0);
|
34
|
-
|
35
|
-
const assetsOverSizeLimit = [];
|
36
|
-
for (const assetName of Object.keys(compilation.assets)) {
|
37
|
-
if (!assetFilter(assetName)) {
|
38
|
-
continue;
|
39
|
-
}
|
40
|
-
|
41
|
-
const asset = compilation.assets[assetName];
|
42
|
-
const size = asset.size();
|
43
|
-
if (size > assetSizeLimit) {
|
44
|
-
assetsOverSizeLimit.push({
|
45
|
-
name: assetName,
|
46
|
-
size: size
|
47
|
-
});
|
48
|
-
asset.isOverSizeLimit = true;
|
49
|
-
}
|
50
|
-
}
|
51
|
-
|
52
|
-
const entrypointsOverLimit = [];
|
53
|
-
for (const pair of compilation.entrypoints) {
|
54
|
-
const name = pair[0];
|
55
|
-
const entry = pair[1];
|
56
|
-
const size = getEntrypointSize(entry
|
57
|
-
|
58
|
-
if (size > entrypointSizeLimit) {
|
59
|
-
entrypointsOverLimit.push({
|
60
|
-
name: name,
|
61
|
-
size: size,
|
62
|
-
files: entry.getFiles().filter(assetFilter)
|
63
|
-
});
|
64
|
-
entry.isOverSizeLimit = true;
|
65
|
-
}
|
66
|
-
}
|
67
|
-
|
68
|
-
if (hints) {
|
69
|
-
// 1. Individual Chunk: Size < 250kb
|
70
|
-
// 2. Collective Initial Chunks [entrypoint] (Each Set?): Size < 250kb
|
71
|
-
// 3. No Async Chunks
|
72
|
-
// if !1, then 2, if !2 return
|
73
|
-
if (assetsOverSizeLimit.length > 0) {
|
74
|
-
warnings.push(
|
75
|
-
new AssetsOverSizeLimitWarning(assetsOverSizeLimit, assetSizeLimit)
|
76
|
-
);
|
77
|
-
}
|
78
|
-
if (entrypointsOverLimit.length > 0) {
|
79
|
-
warnings.push(
|
80
|
-
new EntrypointsOverSizeLimitWarning(
|
81
|
-
entrypointsOverLimit,
|
82
|
-
entrypointSizeLimit
|
83
|
-
)
|
84
|
-
);
|
85
|
-
}
|
86
|
-
|
87
|
-
if (warnings.length > 0) {
|
88
|
-
const hasAsyncChunks =
|
89
|
-
compilation.chunks.filter(chunk => !chunk.canBeInitial()).length >
|
90
|
-
0;
|
91
|
-
|
92
|
-
if (!hasAsyncChunks) {
|
93
|
-
warnings.push(new NoAsyncChunksWarning());
|
94
|
-
}
|
95
|
-
|
96
|
-
if (hints === "error") {
|
97
|
-
compilation.errors.push(...warnings);
|
98
|
-
} else {
|
99
|
-
compilation.warnings.push(...warnings);
|
100
|
-
}
|
101
|
-
}
|
102
|
-
}
|
103
|
-
});
|
104
|
-
}
|
105
|
-
};
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Sean Larkin @thelarkinn
|
4
|
+
*/
|
5
|
+
"use strict";
|
6
|
+
const EntrypointsOverSizeLimitWarning = require("./EntrypointsOverSizeLimitWarning");
|
7
|
+
const AssetsOverSizeLimitWarning = require("./AssetsOverSizeLimitWarning");
|
8
|
+
const NoAsyncChunksWarning = require("./NoAsyncChunksWarning");
|
9
|
+
|
10
|
+
module.exports = class SizeLimitsPlugin {
|
11
|
+
constructor(options) {
|
12
|
+
this.hints = options.hints;
|
13
|
+
this.maxAssetSize = options.maxAssetSize;
|
14
|
+
this.maxEntrypointSize = options.maxEntrypointSize;
|
15
|
+
this.assetFilter = options.assetFilter;
|
16
|
+
}
|
17
|
+
apply(compiler) {
|
18
|
+
const entrypointSizeLimit = this.maxEntrypointSize;
|
19
|
+
const assetSizeLimit = this.maxAssetSize;
|
20
|
+
const hints = this.hints;
|
21
|
+
const assetFilter = this.assetFilter || (asset => !asset.endsWith(".map"));
|
22
|
+
|
23
|
+
compiler.hooks.afterEmit.tap("SizeLimitsPlugin", compilation => {
|
24
|
+
const warnings = [];
|
25
|
+
|
26
|
+
const getEntrypointSize = entrypoint =>
|
27
|
+
entrypoint.getFiles().reduce((currentSize, file) => {
|
28
|
+
if (assetFilter(file) && compilation.assets[file]) {
|
29
|
+
return currentSize + compilation.assets[file].size();
|
30
|
+
}
|
31
|
+
|
32
|
+
return currentSize;
|
33
|
+
}, 0);
|
34
|
+
|
35
|
+
const assetsOverSizeLimit = [];
|
36
|
+
for (const assetName of Object.keys(compilation.assets)) {
|
37
|
+
if (!assetFilter(assetName)) {
|
38
|
+
continue;
|
39
|
+
}
|
40
|
+
|
41
|
+
const asset = compilation.assets[assetName];
|
42
|
+
const size = asset.size();
|
43
|
+
if (size > assetSizeLimit) {
|
44
|
+
assetsOverSizeLimit.push({
|
45
|
+
name: assetName,
|
46
|
+
size: size
|
47
|
+
});
|
48
|
+
asset.isOverSizeLimit = true;
|
49
|
+
}
|
50
|
+
}
|
51
|
+
|
52
|
+
const entrypointsOverLimit = [];
|
53
|
+
for (const pair of compilation.entrypoints) {
|
54
|
+
const name = pair[0];
|
55
|
+
const entry = pair[1];
|
56
|
+
const size = getEntrypointSize(entry);
|
57
|
+
|
58
|
+
if (size > entrypointSizeLimit) {
|
59
|
+
entrypointsOverLimit.push({
|
60
|
+
name: name,
|
61
|
+
size: size,
|
62
|
+
files: entry.getFiles().filter(assetFilter)
|
63
|
+
});
|
64
|
+
entry.isOverSizeLimit = true;
|
65
|
+
}
|
66
|
+
}
|
67
|
+
|
68
|
+
if (hints) {
|
69
|
+
// 1. Individual Chunk: Size < 250kb
|
70
|
+
// 2. Collective Initial Chunks [entrypoint] (Each Set?): Size < 250kb
|
71
|
+
// 3. No Async Chunks
|
72
|
+
// if !1, then 2, if !2 return
|
73
|
+
if (assetsOverSizeLimit.length > 0) {
|
74
|
+
warnings.push(
|
75
|
+
new AssetsOverSizeLimitWarning(assetsOverSizeLimit, assetSizeLimit)
|
76
|
+
);
|
77
|
+
}
|
78
|
+
if (entrypointsOverLimit.length > 0) {
|
79
|
+
warnings.push(
|
80
|
+
new EntrypointsOverSizeLimitWarning(
|
81
|
+
entrypointsOverLimit,
|
82
|
+
entrypointSizeLimit
|
83
|
+
)
|
84
|
+
);
|
85
|
+
}
|
86
|
+
|
87
|
+
if (warnings.length > 0) {
|
88
|
+
const hasAsyncChunks =
|
89
|
+
compilation.chunks.filter(chunk => !chunk.canBeInitial()).length >
|
90
|
+
0;
|
91
|
+
|
92
|
+
if (!hasAsyncChunks) {
|
93
|
+
warnings.push(new NoAsyncChunksWarning());
|
94
|
+
}
|
95
|
+
|
96
|
+
if (hints === "error") {
|
97
|
+
compilation.errors.push(...warnings);
|
98
|
+
} else {
|
99
|
+
compilation.warnings.push(...warnings);
|
100
|
+
}
|
101
|
+
}
|
102
|
+
}
|
103
|
+
});
|
104
|
+
}
|
105
|
+
};
|
package/lib/util/TrackingSet.js
CHANGED
@@ -1,35 +1,35 @@
|
|
1
|
-
/*
|
2
|
-
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
-
Author Tobias Koppers @sokra
|
4
|
-
*/
|
5
|
-
"use strict";
|
6
|
-
|
7
|
-
module.exports = class TrackingSet {
|
8
|
-
constructor(set) {
|
9
|
-
this.set = set;
|
10
|
-
this.set2 = new Set();
|
11
|
-
this.stack = set.stack;
|
12
|
-
}
|
13
|
-
|
14
|
-
add(item) {
|
15
|
-
this.set2.add(item);
|
16
|
-
return this.set.add(item);
|
17
|
-
}
|
18
|
-
|
19
|
-
delete(item) {
|
20
|
-
this.set2.delete(item);
|
21
|
-
return this.set.delete(item);
|
22
|
-
}
|
23
|
-
|
24
|
-
has(item) {
|
25
|
-
return this.set.has(item);
|
26
|
-
}
|
27
|
-
|
28
|
-
createChild() {
|
29
|
-
return this.set.createChild();
|
30
|
-
}
|
31
|
-
|
32
|
-
getAddedItems() {
|
33
|
-
return this.set2;
|
34
|
-
}
|
35
|
-
};
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Tobias Koppers @sokra
|
4
|
+
*/
|
5
|
+
"use strict";
|
6
|
+
|
7
|
+
module.exports = class TrackingSet {
|
8
|
+
constructor(set) {
|
9
|
+
this.set = set;
|
10
|
+
this.set2 = new Set();
|
11
|
+
this.stack = set.stack;
|
12
|
+
}
|
13
|
+
|
14
|
+
add(item) {
|
15
|
+
this.set2.add(item);
|
16
|
+
return this.set.add(item);
|
17
|
+
}
|
18
|
+
|
19
|
+
delete(item) {
|
20
|
+
this.set2.delete(item);
|
21
|
+
return this.set.delete(item);
|
22
|
+
}
|
23
|
+
|
24
|
+
has(item) {
|
25
|
+
return this.set.has(item);
|
26
|
+
}
|
27
|
+
|
28
|
+
createChild() {
|
29
|
+
return this.set.createChild();
|
30
|
+
}
|
31
|
+
|
32
|
+
getAddedItems() {
|
33
|
+
return this.set2;
|
34
|
+
}
|
35
|
+
};
|
package/lib/util/objectToMap.js
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
/**
|
2
|
-
* convert an object into its 2D array equivalent to be turned
|
3
|
-
* into an ES6 map
|
4
|
-
*
|
5
|
-
* @param {object} obj - any object type that works with Object.keys()
|
6
|
-
* @returns {Map} an ES6 Map of KV pairs
|
7
|
-
*/
|
8
|
-
module.exports = function objectToMap(obj) {
|
9
|
-
return new Map(Object.keys(obj).map(key => [key, obj[key]]));
|
10
|
-
};
|
1
|
+
/**
|
2
|
+
* convert an object into its 2D array equivalent to be turned
|
3
|
+
* into an ES6 map
|
4
|
+
*
|
5
|
+
* @param {object} obj - any object type that works with Object.keys()
|
6
|
+
* @returns {Map} an ES6 Map of KV pairs
|
7
|
+
*/
|
8
|
+
module.exports = function objectToMap(obj) {
|
9
|
+
return new Map(Object.keys(obj).map(key => [key, obj[key]]));
|
10
|
+
};
|
@@ -1,106 +1,106 @@
|
|
1
|
-
/*
|
2
|
-
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
-
Author Tobias Koppers @sokra
|
4
|
-
*/
|
5
|
-
"use strict";
|
6
|
-
|
7
|
-
const RawSource = require("webpack-sources")
|
8
|
-
const WebAssemblyImportDependency = require("../dependencies/WebAssemblyImportDependency");
|
9
|
-
|
10
|
-
class WasmModuleTemplatePlugin {
|
11
|
-
apply(moduleTemplate) {
|
12
|
-
moduleTemplate.hooks.content.tap(
|
13
|
-
"WasmModuleTemplatePlugin",
|
14
|
-
(moduleSource, module, { chunk }) => {
|
15
|
-
if (module.type && module.type.startsWith("webassembly")) {
|
16
|
-
if (chunk.canBeInitial())
|
17
|
-
throw new Error(
|
18
|
-
"Sync WebAssembly compilation is not yet implemented"
|
19
|
-
);
|
20
|
-
const generateExports = () => {
|
21
|
-
if (
|
22
|
-
Array.isArray(module.buildMeta.providedExports) &&
|
23
|
-
Array.isArray(module.usedExports)
|
24
|
-
) {
|
25
|
-
// generate mangled exports
|
26
|
-
return module.buildMeta.providedExports
|
27
|
-
.map(exp => {
|
28
|
-
const usedName = module.isUsed(exp);
|
29
|
-
if (usedName) {
|
30
|
-
return `${module.exportsArgument}[${JSON.stringify(
|
31
|
-
usedName
|
32
|
-
)}] = instance.exports[${JSON.stringify(exp)}];`;
|
33
|
-
} else {
|
34
|
-
return `// unused ${JSON.stringify(exp)} export`;
|
35
|
-
}
|
36
|
-
})
|
37
|
-
.join("\n");
|
38
|
-
} else {
|
39
|
-
// generate simple export
|
40
|
-
return `${module.moduleArgument}.exports = instance.exports;`;
|
41
|
-
}
|
42
|
-
};
|
43
|
-
const generateImports = () => {
|
44
|
-
const depsByRequest = new Map();
|
45
|
-
for (const dep of module.dependencies) {
|
46
|
-
if (dep instanceof WebAssemblyImportDependency) {
|
47
|
-
const request = dep.request;
|
48
|
-
let array = depsByRequest.get(request);
|
49
|
-
if (!array) {
|
50
|
-
depsByRequest.set(request, (array = []));
|
51
|
-
}
|
52
|
-
const exportName = dep.name;
|
53
|
-
const usedName = dep.module && dep.module.isUsed(exportName);
|
54
|
-
array.push({
|
55
|
-
exportName,
|
56
|
-
usedName,
|
57
|
-
module: dep.module
|
58
|
-
});
|
59
|
-
}
|
60
|
-
}
|
61
|
-
const importsCode = [];
|
62
|
-
for (const pair of depsByRequest) {
|
63
|
-
const properties = [];
|
64
|
-
for (const data of pair[1]) {
|
65
|
-
properties.push(
|
66
|
-
`\n\t\t${JSON.stringify(
|
67
|
-
data.exportName
|
68
|
-
)}: __webpack_require__(${JSON.stringify(
|
69
|
-
data.module.id
|
70
|
-
)})[${JSON.stringify(data.usedName)}]`
|
71
|
-
);
|
72
|
-
}
|
73
|
-
importsCode.push(
|
74
|
-
`\n\t${JSON.stringify(pair[0])}: {${properties.join(",")}\n\t}`
|
75
|
-
);
|
76
|
-
}
|
77
|
-
return importsCode.join(",");
|
78
|
-
};
|
79
|
-
const source = new RawSource(
|
80
|
-
[
|
81
|
-
'"use strict";',
|
82
|
-
"",
|
83
|
-
"// Instantiate WebAssembly module",
|
84
|
-
"var instance = new WebAssembly.Instance(__webpack_require__.w[module.i], {" +
|
85
|
-
generateImports(),
|
86
|
-
"});",
|
87
|
-
"",
|
88
|
-
"// export exports from WebAssembly module",
|
89
|
-
// TODO rewrite this to getters depending on exports to support circular dependencies
|
90
|
-
generateExports()
|
91
|
-
].join("\n")
|
92
|
-
);
|
93
|
-
return source;
|
94
|
-
} else {
|
95
|
-
return moduleSource;
|
96
|
-
}
|
97
|
-
}
|
98
|
-
);
|
99
|
-
|
100
|
-
moduleTemplate.hooks.hash.tap("WasmModuleTemplatePlugin", hash => {
|
101
|
-
hash.update("WasmModuleTemplatePlugin");
|
102
|
-
hash.update("1");
|
103
|
-
});
|
104
|
-
}
|
105
|
-
}
|
106
|
-
module.exports = WasmModuleTemplatePlugin;
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Tobias Koppers @sokra
|
4
|
+
*/
|
5
|
+
"use strict";
|
6
|
+
|
7
|
+
const { RawSource } = require("webpack-sources");
|
8
|
+
const WebAssemblyImportDependency = require("../dependencies/WebAssemblyImportDependency");
|
9
|
+
|
10
|
+
class WasmModuleTemplatePlugin {
|
11
|
+
apply(moduleTemplate) {
|
12
|
+
moduleTemplate.hooks.content.tap(
|
13
|
+
"WasmModuleTemplatePlugin",
|
14
|
+
(moduleSource, module, { chunk }) => {
|
15
|
+
if (module.type && module.type.startsWith("webassembly")) {
|
16
|
+
if (chunk.canBeInitial())
|
17
|
+
throw new Error(
|
18
|
+
"Sync WebAssembly compilation is not yet implemented"
|
19
|
+
);
|
20
|
+
const generateExports = () => {
|
21
|
+
if (
|
22
|
+
Array.isArray(module.buildMeta.providedExports) &&
|
23
|
+
Array.isArray(module.usedExports)
|
24
|
+
) {
|
25
|
+
// generate mangled exports
|
26
|
+
return module.buildMeta.providedExports
|
27
|
+
.map(exp => {
|
28
|
+
const usedName = module.isUsed(exp);
|
29
|
+
if (usedName) {
|
30
|
+
return `${module.exportsArgument}[${JSON.stringify(
|
31
|
+
usedName
|
32
|
+
)}] = instance.exports[${JSON.stringify(exp)}];`;
|
33
|
+
} else {
|
34
|
+
return `// unused ${JSON.stringify(exp)} export`;
|
35
|
+
}
|
36
|
+
})
|
37
|
+
.join("\n");
|
38
|
+
} else {
|
39
|
+
// generate simple export
|
40
|
+
return `${module.moduleArgument}.exports = instance.exports;`;
|
41
|
+
}
|
42
|
+
};
|
43
|
+
const generateImports = () => {
|
44
|
+
const depsByRequest = new Map();
|
45
|
+
for (const dep of module.dependencies) {
|
46
|
+
if (dep instanceof WebAssemblyImportDependency) {
|
47
|
+
const request = dep.request;
|
48
|
+
let array = depsByRequest.get(request);
|
49
|
+
if (!array) {
|
50
|
+
depsByRequest.set(request, (array = []));
|
51
|
+
}
|
52
|
+
const exportName = dep.name;
|
53
|
+
const usedName = dep.module && dep.module.isUsed(exportName);
|
54
|
+
array.push({
|
55
|
+
exportName,
|
56
|
+
usedName,
|
57
|
+
module: dep.module
|
58
|
+
});
|
59
|
+
}
|
60
|
+
}
|
61
|
+
const importsCode = [];
|
62
|
+
for (const pair of depsByRequest) {
|
63
|
+
const properties = [];
|
64
|
+
for (const data of pair[1]) {
|
65
|
+
properties.push(
|
66
|
+
`\n\t\t${JSON.stringify(
|
67
|
+
data.exportName
|
68
|
+
)}: __webpack_require__(${JSON.stringify(
|
69
|
+
data.module.id
|
70
|
+
)})[${JSON.stringify(data.usedName)}]`
|
71
|
+
);
|
72
|
+
}
|
73
|
+
importsCode.push(
|
74
|
+
`\n\t${JSON.stringify(pair[0])}: {${properties.join(",")}\n\t}`
|
75
|
+
);
|
76
|
+
}
|
77
|
+
return importsCode.join(",");
|
78
|
+
};
|
79
|
+
const source = new RawSource(
|
80
|
+
[
|
81
|
+
'"use strict";',
|
82
|
+
"",
|
83
|
+
"// Instantiate WebAssembly module",
|
84
|
+
"var instance = new WebAssembly.Instance(__webpack_require__.w[module.i], {" +
|
85
|
+
generateImports(),
|
86
|
+
"});",
|
87
|
+
"",
|
88
|
+
"// export exports from WebAssembly module",
|
89
|
+
// TODO rewrite this to getters depending on exports to support circular dependencies
|
90
|
+
generateExports()
|
91
|
+
].join("\n")
|
92
|
+
);
|
93
|
+
return source;
|
94
|
+
} else {
|
95
|
+
return moduleSource;
|
96
|
+
}
|
97
|
+
}
|
98
|
+
);
|
99
|
+
|
100
|
+
moduleTemplate.hooks.hash.tap("WasmModuleTemplatePlugin", hash => {
|
101
|
+
hash.update("WasmModuleTemplatePlugin");
|
102
|
+
hash.update("1");
|
103
|
+
});
|
104
|
+
}
|
105
|
+
}
|
106
|
+
module.exports = WasmModuleTemplatePlugin;
|
@@ -1,47 +1,47 @@
|
|
1
|
-
/*
|
2
|
-
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
-
Author Tobias Koppers @sokra
|
4
|
-
*/
|
5
|
-
"use strict";
|
6
|
-
|
7
|
-
const ConcatSource = require("webpack-sources")
|
8
|
-
|
9
|
-
class JsonpChunkTemplatePlugin {
|
10
|
-
apply(chunkTemplate) {
|
11
|
-
chunkTemplate.hooks.render.tap(
|
12
|
-
"JsonpChunkTemplatePlugin",
|
13
|
-
(modules, chunk) => {
|
14
|
-
const jsonpFunction = chunkTemplate.outputOptions.jsonpFunction;
|
15
|
-
const globalObject = chunkTemplate.outputOptions.globalObject;
|
16
|
-
const source = new ConcatSource();
|
17
|
-
source.add(
|
18
|
-
`(${globalObject}[${JSON.stringify(
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
)},`
|
23
|
-
);
|
24
|
-
source.add(modules);
|
25
|
-
const entries = [chunk.entryModule].filter(Boolean).map(m =>
|
26
|
-
[m.id].concat(
|
27
|
-
Array.from(chunk.groupsIterable)[0]
|
28
|
-
.chunks.filter(c => c !== chunk)
|
29
|
-
.map(c => c.id)
|
30
|
-
)
|
31
|
-
);
|
32
|
-
if (entries.length > 0) {
|
33
|
-
source.add(`,${JSON.stringify(entries)}`);
|
34
|
-
}
|
35
|
-
source.add("])");
|
36
|
-
return source;
|
37
|
-
}
|
38
|
-
);
|
39
|
-
chunkTemplate.hooks.hash.tap("JsonpChunkTemplatePlugin", hash => {
|
40
|
-
hash.update("JsonpChunkTemplatePlugin");
|
41
|
-
hash.update("4");
|
42
|
-
hash.update(`${chunkTemplate.outputOptions.jsonpFunction}`);
|
43
|
-
hash.update(`${chunkTemplate.outputOptions.globalObject}`);
|
44
|
-
});
|
45
|
-
}
|
46
|
-
}
|
47
|
-
module.exports = JsonpChunkTemplatePlugin;
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Tobias Koppers @sokra
|
4
|
+
*/
|
5
|
+
"use strict";
|
6
|
+
|
7
|
+
const { ConcatSource } = require("webpack-sources");
|
8
|
+
|
9
|
+
class JsonpChunkTemplatePlugin {
|
10
|
+
apply(chunkTemplate) {
|
11
|
+
chunkTemplate.hooks.render.tap(
|
12
|
+
"JsonpChunkTemplatePlugin",
|
13
|
+
(modules, chunk) => {
|
14
|
+
const jsonpFunction = chunkTemplate.outputOptions.jsonpFunction;
|
15
|
+
const globalObject = chunkTemplate.outputOptions.globalObject;
|
16
|
+
const source = new ConcatSource();
|
17
|
+
source.add(
|
18
|
+
`(${globalObject}[${JSON.stringify(
|
19
|
+
jsonpFunction
|
20
|
+
)}] = ${globalObject}[${JSON.stringify(
|
21
|
+
jsonpFunction
|
22
|
+
)}] || []).push([${JSON.stringify(chunk.ids)},`
|
23
|
+
);
|
24
|
+
source.add(modules);
|
25
|
+
const entries = [chunk.entryModule].filter(Boolean).map(m =>
|
26
|
+
[m.id].concat(
|
27
|
+
Array.from(chunk.groupsIterable)[0]
|
28
|
+
.chunks.filter(c => c !== chunk)
|
29
|
+
.map(c => c.id)
|
30
|
+
)
|
31
|
+
);
|
32
|
+
if (entries.length > 0) {
|
33
|
+
source.add(`,${JSON.stringify(entries)}`);
|
34
|
+
}
|
35
|
+
source.add("])");
|
36
|
+
return source;
|
37
|
+
}
|
38
|
+
);
|
39
|
+
chunkTemplate.hooks.hash.tap("JsonpChunkTemplatePlugin", hash => {
|
40
|
+
hash.update("JsonpChunkTemplatePlugin");
|
41
|
+
hash.update("4");
|
42
|
+
hash.update(`${chunkTemplate.outputOptions.jsonpFunction}`);
|
43
|
+
hash.update(`${chunkTemplate.outputOptions.globalObject}`);
|
44
|
+
});
|
45
|
+
}
|
46
|
+
}
|
47
|
+
module.exports = JsonpChunkTemplatePlugin;
|