webpack 4.10.1 → 4.12.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/lib/AmdMainTemplatePlugin.js +3 -1
- package/lib/AsyncDependencyToInitialChunkError.js +4 -4
- package/lib/BannerPlugin.js +3 -1
- package/lib/BasicEvaluatedExpression.js +14 -11
- package/lib/CachePlugin.js +12 -5
- package/lib/CaseSensitiveModulesWarning.js +41 -45
- package/lib/Chunk.js +56 -19
- package/lib/ChunkGroup.js +14 -6
- package/lib/CommentCompilationWarning.js +22 -0
- package/lib/Compilation.js +72 -29
- package/lib/Compiler.js +22 -10
- package/lib/ConstPlugin.js +25 -9
- package/lib/ContextModule.js +88 -36
- package/lib/ContextModuleFactory.js +18 -7
- package/lib/ContextReplacementPlugin.js +14 -7
- package/lib/DefinePlugin.js +15 -6
- package/lib/DependenciesBlock.js +3 -1
- package/lib/DependenciesBlockVariable.js +2 -1
- package/lib/DllPlugin.js +4 -2
- package/lib/DynamicEntryPlugin.js +4 -2
- package/lib/EntryModuleNotFoundError.js +21 -22
- package/lib/ErrorHelpers.js +5 -2
- package/lib/EvalSourceMapDevToolPlugin.js +2 -1
- package/lib/FlagDependencyUsagePlugin.js +11 -5
- package/lib/FunctionModuleTemplatePlugin.js +8 -6
- package/lib/HarmonyLinkingError.js +1 -2
- package/lib/HotModuleReplacement.runtime.js +13 -4
- package/lib/HotModuleReplacementPlugin.js +13 -6
- package/lib/JavascriptGenerator.js +2 -1
- package/lib/JavascriptModulesPlugin.js +4 -9
- package/lib/JsonParser.js +2 -1
- package/lib/LibraryTemplatePlugin.js +2 -1
- package/lib/LoaderOptionsPlugin.js +2 -1
- package/lib/MainTemplate.js +2 -1
- package/lib/Module.js +13 -5
- package/lib/ModuleBuildError.js +22 -12
- package/lib/ModuleDependencyError.js +4 -4
- package/lib/ModuleDependencyWarning.js +4 -4
- package/lib/ModuleError.js +13 -5
- package/lib/ModuleFilenameHelpers.js +20 -8
- package/lib/ModuleNotFoundError.js +23 -26
- package/lib/ModuleParseError.js +27 -14
- package/lib/ModuleWarning.js +13 -7
- package/lib/MultiCompiler.js +19 -7
- package/lib/MultiModule.js +5 -2
- package/lib/NodeStuffPlugin.js +2 -1
- package/lib/NormalModule.js +80 -16
- package/lib/NormalModuleFactory.js +67 -24
- package/lib/OptionsDefaulter.js +7 -3
- package/lib/Parser.js +182 -75
- package/lib/ParserHelpers.js +6 -3
- package/lib/ProgressPlugin.js +17 -2
- package/lib/RawModule.js +4 -2
- package/lib/RecordIdsPlugin.js +77 -9
- package/lib/RemovedPluginError.js +1 -3
- package/lib/RequestShortener.js +15 -6
- package/lib/RuleSet.js +51 -18
- package/lib/RuntimeTemplate.js +21 -10
- package/lib/SourceMapDevToolPlugin.js +4 -3
- package/lib/Stats.js +74 -31
- package/lib/Template.js +7 -4
- package/lib/TemplatedPathPlugin.js +6 -3
- package/lib/UmdMainTemplatePlugin.js +8 -3
- package/lib/UnsupportedFeatureWarning.js +22 -21
- package/lib/WarnCaseSensitiveModulesPlugin.js +2 -1
- package/lib/Watching.js +3 -2
- package/lib/WebpackOptionsApply.js +51 -23
- package/lib/WebpackOptionsDefaulter.js +15 -9
- package/lib/WebpackOptionsValidationError.js +63 -34
- package/lib/debug/ProfilingPlugin.js +11 -2
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +17 -8
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +8 -4
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +4 -2
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +7 -3
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +6 -3
- package/lib/dependencies/ImportParserPlugin.js +42 -11
- package/lib/dependencies/LoaderPlugin.js +12 -7
- package/lib/dependencies/LocalModulesHelpers.js +13 -6
- package/lib/dependencies/RequireContextPlugin.js +4 -2
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +8 -4
- package/lib/dependencies/SystemPlugin.js +6 -6
- package/lib/dependencies/WebAssemblyExportImportedDependency.js +29 -0
- package/lib/dependencies/WebAssemblyImportDependency.js +1 -1
- package/lib/formatLocation.js +15 -7
- package/lib/node/NodeMainTemplateAsync.runtime.js +1 -1
- package/lib/node/NodeMainTemplatePlugin.js +6 -3
- package/lib/node/NodeSourcePlugin.js +9 -5
- package/lib/node/NodeWatchFileSystem.js +29 -12
- package/lib/node/ReadFileCompileWasmTemplatePlugin.js +11 -2
- package/lib/optimize/AggressiveSplittingPlugin.js +12 -6
- package/lib/optimize/ConcatenatedModule.js +19 -8
- package/lib/optimize/MergeDuplicateChunksPlugin.js +6 -3
- package/lib/optimize/ModuleConcatenationPlugin.js +23 -10
- package/lib/optimize/OccurrenceOrderPlugin.js +11 -4
- package/lib/optimize/RemoveParentModulesPlugin.js +17 -7
- package/lib/optimize/SideEffectsFlagPlugin.js +14 -3
- package/lib/optimize/SplitChunksPlugin.js +33 -20
- package/lib/performance/AssetsOverSizeLimitWarning.js +7 -7
- package/lib/performance/EntrypointsOverSizeLimitWarning.js +6 -7
- package/lib/performance/NoAsyncChunksWarning.js +5 -5
- package/lib/util/SortableSet.js +5 -2
- package/lib/util/StackedSetMap.js +12 -5
- package/lib/wasm/UnsupportedWebAssemblyFeatureError.js +1 -2
- package/lib/wasm/WasmFinalizeExportsPlugin.js +66 -0
- package/lib/wasm/WasmMainTemplatePlugin.js +87 -43
- package/lib/wasm/WebAssemblyGenerator.js +117 -74
- package/lib/wasm/WebAssemblyJavascriptGenerator.js +92 -49
- package/lib/wasm/WebAssemblyModulesPlugin.js +11 -1
- package/lib/wasm/WebAssemblyParser.js +96 -24
- package/lib/wasm/WebAssemblyUtils.js +17 -6
- package/lib/web/FetchCompileWasmTemplatePlugin.js +13 -1
- package/lib/web/JsonpChunkTemplatePlugin.js +7 -0
- package/lib/web/JsonpMainTemplate.runtime.js +2 -1
- package/lib/web/JsonpMainTemplatePlugin.js +68 -63
- package/lib/webpack.js +2 -1
- package/lib/webworker/WebWorkerMainTemplate.runtime.js +2 -1
- package/package.json +12 -11
- package/schemas/WebpackOptions.json +8 -0
@@ -6,36 +6,27 @@
|
|
6
6
|
|
7
7
|
const t = require("@webassemblyjs/ast");
|
8
8
|
const { decode } = require("@webassemblyjs/wasm-parser");
|
9
|
+
const {
|
10
|
+
moduleContextFromModuleAST
|
11
|
+
} = require("@webassemblyjs/helper-module-context");
|
9
12
|
|
10
13
|
const { Tapable } = require("tapable");
|
11
14
|
const WebAssemblyImportDependency = require("../dependencies/WebAssemblyImportDependency");
|
15
|
+
const WebAssemblyExportImportedDependency = require("../dependencies/WebAssemblyExportImportedDependency");
|
12
16
|
|
13
17
|
/** @typedef {import("../Module")} Module */
|
14
18
|
|
15
|
-
/**
|
16
|
-
* @param {t.ModuleImport} n the import
|
17
|
-
* @returns {boolean} true, if a memory was imported
|
18
|
-
*/
|
19
|
-
const isMemoryImport = n => n.descr.type === "Memory";
|
20
|
-
|
21
|
-
/**
|
22
|
-
* @param {t.ModuleImport} n the import
|
23
|
-
* @returns {boolean} true, if a table was imported
|
24
|
-
*/
|
25
|
-
const isTableImport = n => n.descr.type === "Table";
|
26
|
-
|
27
19
|
const JS_COMPAT_TYPES = new Set(["i32", "f32", "f64"]);
|
28
20
|
|
29
21
|
/**
|
30
|
-
* @param {t.
|
22
|
+
* @param {t.Signature} signature the func signature
|
31
23
|
* @returns {null | string} the type incompatible with js types
|
32
24
|
*/
|
33
|
-
const getJsIncompatibleType =
|
34
|
-
if (moduleImport.descr.type !== "FuncImportDescr") return null;
|
35
|
-
const signature = moduleImport.descr.signature;
|
25
|
+
const getJsIncompatibleType = signature => {
|
36
26
|
for (const param of signature.params) {
|
37
|
-
if (!JS_COMPAT_TYPES.has(param.valtype))
|
27
|
+
if (!JS_COMPAT_TYPES.has(param.valtype)) {
|
38
28
|
return `${param.valtype} as parameter`;
|
29
|
+
}
|
39
30
|
}
|
40
31
|
for (const type of signature.results) {
|
41
32
|
if (!JS_COMPAT_TYPES.has(type)) return `${type} as result`;
|
@@ -43,9 +34,29 @@ const getJsIncompatibleType = moduleImport => {
|
|
43
34
|
return null;
|
44
35
|
};
|
45
36
|
|
37
|
+
/**
|
38
|
+
* TODO why are there two different Signature types?
|
39
|
+
* @param {t.FuncSignature} signature the func signature
|
40
|
+
* @returns {null | string} the type incompatible with js types
|
41
|
+
*/
|
42
|
+
const getJsIncompatibleTypeOfFuncSignature = signature => {
|
43
|
+
for (const param of signature.args) {
|
44
|
+
if (!JS_COMPAT_TYPES.has(param)) {
|
45
|
+
return `${param} as parameter`;
|
46
|
+
}
|
47
|
+
}
|
48
|
+
for (const type of signature.result) {
|
49
|
+
if (!JS_COMPAT_TYPES.has(type)) return `${type} as result`;
|
50
|
+
}
|
51
|
+
return null;
|
52
|
+
};
|
53
|
+
|
46
54
|
const decoderOpts = {
|
47
55
|
ignoreCodeSection: true,
|
48
|
-
ignoreDataSection: true
|
56
|
+
ignoreDataSection: true,
|
57
|
+
|
58
|
+
// this will avoid having to lookup with identifiers in the ModuleContext
|
59
|
+
ignoreCustomNameSection: true
|
49
60
|
};
|
50
61
|
|
51
62
|
class WebAssemblyParser extends Tapable {
|
@@ -60,28 +71,85 @@ class WebAssemblyParser extends Tapable {
|
|
60
71
|
state.module.buildMeta.exportsType = "namespace";
|
61
72
|
|
62
73
|
// parse it
|
63
|
-
const
|
74
|
+
const program = decode(binary, decoderOpts);
|
75
|
+
const module = program.body[0];
|
76
|
+
|
77
|
+
const moduleContext = moduleContextFromModuleAST(module);
|
64
78
|
|
65
79
|
// extract imports and exports
|
66
80
|
const exports = (state.module.buildMeta.providedExports = []);
|
67
|
-
|
81
|
+
const jsIncompatibleExports = (state.module.buildMeta.jsIncompatibleExports = []);
|
82
|
+
|
83
|
+
const importedGlobals = [];
|
84
|
+
t.traverse(module, {
|
68
85
|
ModuleExport({ node }) {
|
86
|
+
const descriptor = node.descr;
|
87
|
+
|
88
|
+
if (descriptor.exportType === "Func") {
|
89
|
+
const funcidx = descriptor.id.value;
|
90
|
+
|
91
|
+
/** @type {t.FuncSignature} */
|
92
|
+
const funcSignature = moduleContext.getFunction(funcidx);
|
93
|
+
|
94
|
+
const incompatibleType = getJsIncompatibleTypeOfFuncSignature(
|
95
|
+
funcSignature
|
96
|
+
);
|
97
|
+
|
98
|
+
if (incompatibleType) {
|
99
|
+
jsIncompatibleExports[node.name] = incompatibleType;
|
100
|
+
}
|
101
|
+
}
|
102
|
+
|
69
103
|
exports.push(node.name);
|
104
|
+
|
105
|
+
if (node.descr && node.descr.exportType === "Global") {
|
106
|
+
const refNode = importedGlobals[node.descr.id.value];
|
107
|
+
if (refNode) {
|
108
|
+
const dep = new WebAssemblyExportImportedDependency(
|
109
|
+
node.name,
|
110
|
+
refNode.module,
|
111
|
+
refNode.name
|
112
|
+
);
|
113
|
+
|
114
|
+
state.module.addDependency(dep);
|
115
|
+
}
|
116
|
+
}
|
117
|
+
},
|
118
|
+
|
119
|
+
Global({ node }) {
|
120
|
+
const init = node.init[0];
|
121
|
+
|
122
|
+
let importNode = null;
|
123
|
+
|
124
|
+
if (init.id === "get_global") {
|
125
|
+
const globalIdx = init.args[0].value;
|
126
|
+
|
127
|
+
if (globalIdx < importedGlobals.length) {
|
128
|
+
importNode = importedGlobals[globalIdx];
|
129
|
+
}
|
130
|
+
}
|
131
|
+
|
132
|
+
importedGlobals.push(importNode);
|
70
133
|
},
|
71
134
|
|
72
135
|
ModuleImport({ node }) {
|
73
136
|
/** @type {false | string} */
|
74
137
|
let onlyDirectImport = false;
|
75
138
|
|
76
|
-
if (
|
139
|
+
if (t.isMemory(node.descr) === true) {
|
77
140
|
onlyDirectImport = "Memory";
|
78
|
-
} else if (
|
141
|
+
} else if (t.isTable(node.descr) === true) {
|
79
142
|
onlyDirectImport = "Table";
|
80
|
-
} else {
|
81
|
-
const incompatibleType = getJsIncompatibleType(node);
|
143
|
+
} else if (t.isFuncImportDescr(node.descr) === true) {
|
144
|
+
const incompatibleType = getJsIncompatibleType(node.descr.signature);
|
82
145
|
if (incompatibleType) {
|
83
146
|
onlyDirectImport = `Non-JS-compatible Func Sigurature (${incompatibleType})`;
|
84
147
|
}
|
148
|
+
} else if (t.isGlobalType(node.descr) === true) {
|
149
|
+
const type = node.descr.valtype;
|
150
|
+
if (!JS_COMPAT_TYPES.has(type)) {
|
151
|
+
onlyDirectImport = `Non-JS-compatible Global Type (${type})`;
|
152
|
+
}
|
85
153
|
}
|
86
154
|
|
87
155
|
const dep = new WebAssemblyImportDependency(
|
@@ -92,6 +160,10 @@ class WebAssemblyParser extends Tapable {
|
|
92
160
|
);
|
93
161
|
|
94
162
|
state.module.addDependency(dep);
|
163
|
+
|
164
|
+
if (t.isGlobalType(node.descr)) {
|
165
|
+
importedGlobals.push(node);
|
166
|
+
}
|
95
167
|
}
|
96
168
|
});
|
97
169
|
|
@@ -12,15 +12,17 @@ const WebAssemblyImportDependency = require("../dependencies/WebAssemblyImportDe
|
|
12
12
|
/** @typedef {Object} UsedWasmDependency
|
13
13
|
* @property {WebAssemblyImportDependency} dependency the dependency
|
14
14
|
* @property {string} name the export name
|
15
|
+
* @property {string} module the module name
|
15
16
|
*/
|
16
17
|
|
17
18
|
const MANGLED_MODULE = "a";
|
18
19
|
|
19
20
|
/**
|
20
21
|
* @param {Module} module the module
|
21
|
-
* @
|
22
|
+
* @param {boolean} mangle mangle module and export names
|
23
|
+
* @returns {UsedWasmDependency[]} used dependencies and (mangled) name
|
22
24
|
*/
|
23
|
-
const getUsedDependencies = module => {
|
25
|
+
const getUsedDependencies = (module, mangle) => {
|
24
26
|
/** @type {UsedWasmDependency[]} */
|
25
27
|
const array = [];
|
26
28
|
let importIndex = 0;
|
@@ -30,13 +32,22 @@ const getUsedDependencies = module => {
|
|
30
32
|
continue;
|
31
33
|
}
|
32
34
|
|
33
|
-
const importedModule = dep.module;
|
34
35
|
const exportName = dep.name;
|
35
|
-
|
36
|
-
|
36
|
+
// TODO add the following 3 lines when removing of ModuleExport is possible
|
37
|
+
// const importedModule = dep.module;
|
38
|
+
// const usedName = importedModule && importedModule.isUsed(exportName);
|
39
|
+
// if (usedName !== false) {
|
40
|
+
if (mangle) {
|
37
41
|
array.push({
|
38
42
|
dependency: dep,
|
39
|
-
name: Template.numberToIdentifer(importIndex++)
|
43
|
+
name: Template.numberToIdentifer(importIndex++),
|
44
|
+
module: MANGLED_MODULE
|
45
|
+
});
|
46
|
+
} else {
|
47
|
+
array.push({
|
48
|
+
dependency: dep,
|
49
|
+
name: exportName,
|
50
|
+
module: dep.request
|
40
51
|
});
|
41
52
|
}
|
42
53
|
}
|
@@ -7,6 +7,10 @@
|
|
7
7
|
const WasmMainTemplatePlugin = require("../wasm/WasmMainTemplatePlugin");
|
8
8
|
|
9
9
|
class FetchCompileWasmTemplatePlugin {
|
10
|
+
constructor(options) {
|
11
|
+
this.options = options || {};
|
12
|
+
}
|
13
|
+
|
10
14
|
apply(compiler) {
|
11
15
|
compiler.hooks.thisCompilation.tap(
|
12
16
|
"FetchCompileWasmTemplatePlugin",
|
@@ -15,7 +19,15 @@ class FetchCompileWasmTemplatePlugin {
|
|
15
19
|
const generateLoadBinaryCode = path =>
|
16
20
|
`fetch(${mainTemplate.requireFn}.p + ${path})`;
|
17
21
|
|
18
|
-
const plugin = new WasmMainTemplatePlugin(
|
22
|
+
const plugin = new WasmMainTemplatePlugin(
|
23
|
+
Object.assign(
|
24
|
+
{
|
25
|
+
generateLoadBinaryCode,
|
26
|
+
supportsStreaming: true
|
27
|
+
},
|
28
|
+
this.options
|
29
|
+
)
|
30
|
+
);
|
19
31
|
plugin.apply(mainTemplate);
|
20
32
|
}
|
21
33
|
);
|
@@ -14,6 +14,7 @@ class JsonpChunkTemplatePlugin {
|
|
14
14
|
const jsonpFunction = chunkTemplate.outputOptions.jsonpFunction;
|
15
15
|
const globalObject = chunkTemplate.outputOptions.globalObject;
|
16
16
|
const source = new ConcatSource();
|
17
|
+
const prefetchChunks = chunk.getChildIdsByOrders().prefetch;
|
17
18
|
source.add(
|
18
19
|
`(${globalObject}[${JSON.stringify(
|
19
20
|
jsonpFunction
|
@@ -31,6 +32,12 @@ class JsonpChunkTemplatePlugin {
|
|
31
32
|
);
|
32
33
|
if (entries.length > 0) {
|
33
34
|
source.add(`,${JSON.stringify(entries)}`);
|
35
|
+
} else if (prefetchChunks && prefetchChunks.length) {
|
36
|
+
source.add(`,0`);
|
37
|
+
}
|
38
|
+
|
39
|
+
if (prefetchChunks && prefetchChunks.length) {
|
40
|
+
source.add(`,${JSON.stringify(prefetchChunks)}`);
|
34
41
|
}
|
35
42
|
source.add("])");
|
36
43
|
return source;
|
@@ -24,8 +24,9 @@ module.exports = function() {
|
|
24
24
|
function hotDownloadManifest(requestTimeout) {
|
25
25
|
requestTimeout = requestTimeout || 10000;
|
26
26
|
return new Promise(function(resolve, reject) {
|
27
|
-
if (typeof XMLHttpRequest === "undefined")
|
27
|
+
if (typeof XMLHttpRequest === "undefined") {
|
28
28
|
return reject(new Error("No browser support"));
|
29
|
+
}
|
29
30
|
try {
|
30
31
|
var request = new XMLHttpRequest();
|
31
32
|
var requestPath = $require$.p + $hotMainFilename$;
|
@@ -28,28 +28,21 @@ class JsonpMainTemplatePlugin {
|
|
28
28
|
}
|
29
29
|
return false;
|
30
30
|
};
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
}
|
46
|
-
if (!mainTemplate.hooks.linkPrefetch) {
|
47
|
-
mainTemplate.hooks.linkPrefetch = new SyncWaterfallHook([
|
48
|
-
"source",
|
49
|
-
"chunk",
|
50
|
-
"hash"
|
51
|
-
]);
|
52
|
-
}
|
31
|
+
const needPrefetchingCode = chunk => {
|
32
|
+
const allPrefetchChunks = chunk.getChildIdsByOrdersMap(true).prefetch;
|
33
|
+
return allPrefetchChunks && Object.keys(allPrefetchChunks).length;
|
34
|
+
};
|
35
|
+
|
36
|
+
// TODO webpack 5, no adding to .hooks, use WeakMap and static methods
|
37
|
+
["jsonpScript", "linkPreload", "linkPrefetch"].forEach(hook => {
|
38
|
+
if (!mainTemplate.hooks[hook]) {
|
39
|
+
mainTemplate.hooks[hook] = new SyncWaterfallHook([
|
40
|
+
"source",
|
41
|
+
"chunk",
|
42
|
+
"hash"
|
43
|
+
]);
|
44
|
+
}
|
45
|
+
});
|
53
46
|
|
54
47
|
const getScriptSrcPath = (hash, chunk, chunkIdExpression) => {
|
55
48
|
const chunkFilename = mainTemplate.outputOptions.chunkFilename;
|
@@ -66,11 +59,12 @@ class JsonpMainTemplatePlugin {
|
|
66
59
|
hashWithLength(length) {
|
67
60
|
const shortChunkHashMap = Object.create(null);
|
68
61
|
for (const chunkId of Object.keys(chunkMaps.hash)) {
|
69
|
-
if (typeof chunkMaps.hash[chunkId] === "string")
|
62
|
+
if (typeof chunkMaps.hash[chunkId] === "string") {
|
70
63
|
shortChunkHashMap[chunkId] = chunkMaps.hash[chunkId].substr(
|
71
64
|
0,
|
72
65
|
length
|
73
66
|
);
|
67
|
+
}
|
74
68
|
}
|
75
69
|
return `" + ${JSON.stringify(
|
76
70
|
shortChunkHashMap
|
@@ -231,9 +225,21 @@ class JsonpMainTemplatePlugin {
|
|
231
225
|
mainTemplate.hooks.linkPrefetch.tap(
|
232
226
|
"JsonpMainTemplatePlugin",
|
233
227
|
(_, chunk, hash) => {
|
228
|
+
const crossOriginLoading =
|
229
|
+
mainTemplate.outputOptions.crossOriginLoading;
|
230
|
+
|
234
231
|
return Template.asString([
|
235
232
|
"var link = document.createElement('link');",
|
233
|
+
crossOriginLoading
|
234
|
+
? `link.crossOrigin = ${JSON.stringify(crossOriginLoading)};`
|
235
|
+
: "",
|
236
|
+
`if (${mainTemplate.requireFn}.nc) {`,
|
237
|
+
Template.indent(
|
238
|
+
`link.setAttribute("nonce", ${mainTemplate.requireFn}.nc);`
|
239
|
+
),
|
240
|
+
"}",
|
236
241
|
'link.rel = "prefetch";',
|
242
|
+
'link.as = "script";',
|
237
243
|
"link.href = jsonpScriptSrc(chunkId);"
|
238
244
|
]);
|
239
245
|
}
|
@@ -287,7 +293,7 @@ class JsonpMainTemplatePlugin {
|
|
287
293
|
"",
|
288
294
|
"// chunk preloadng for javascript",
|
289
295
|
"",
|
290
|
-
`var chunkPreloadMap = ${JSON.stringify(chunkMap, null, "\t")}
|
296
|
+
`var chunkPreloadMap = ${JSON.stringify(chunkMap, null, "\t")};`,
|
291
297
|
"",
|
292
298
|
"var chunkPreloadData = chunkPreloadMap[chunkId];",
|
293
299
|
"if(chunkPreloadData) {",
|
@@ -309,45 +315,6 @@ class JsonpMainTemplatePlugin {
|
|
309
315
|
]);
|
310
316
|
}
|
311
317
|
);
|
312
|
-
mainTemplate.hooks.requireEnsure.tap(
|
313
|
-
{
|
314
|
-
name: "JsonpMainTemplatePlugin prefetch",
|
315
|
-
stage: 20
|
316
|
-
},
|
317
|
-
(source, chunk, hash) => {
|
318
|
-
const chunkMap = chunk.getChildIdsByOrdersMap().prefetch;
|
319
|
-
if (!chunkMap || Object.keys(chunkMap).length === 0) return source;
|
320
|
-
return Template.asString([
|
321
|
-
source,
|
322
|
-
"",
|
323
|
-
"// chunk prefetching for javascript",
|
324
|
-
"",
|
325
|
-
`var chunkPrefetchMap = ${JSON.stringify(chunkMap, null, "\t")}`,
|
326
|
-
"",
|
327
|
-
"var chunkPrefetchData = chunkPrefetchMap[chunkId];",
|
328
|
-
"if(chunkPrefetchData) {",
|
329
|
-
Template.indent([
|
330
|
-
"Promise.all(promises).then(function() {",
|
331
|
-
Template.indent([
|
332
|
-
"var head = document.getElementsByTagName('head')[0];",
|
333
|
-
"chunkPrefetchData.forEach(function(chunkId) {",
|
334
|
-
Template.indent([
|
335
|
-
"if(installedChunks[chunkId] === undefined) {",
|
336
|
-
Template.indent([
|
337
|
-
"installedChunks[chunkId] = null;",
|
338
|
-
mainTemplate.hooks.linkPrefetch.call("", chunk, hash),
|
339
|
-
"head.appendChild(link);"
|
340
|
-
]),
|
341
|
-
"}"
|
342
|
-
]),
|
343
|
-
"});"
|
344
|
-
]),
|
345
|
-
"})"
|
346
|
-
]),
|
347
|
-
"}"
|
348
|
-
]);
|
349
|
-
}
|
350
|
-
);
|
351
318
|
mainTemplate.hooks.requireExtensions.tap(
|
352
319
|
"JsonpMainTemplatePlugin",
|
353
320
|
(source, chunk) => {
|
@@ -368,6 +335,7 @@ class JsonpMainTemplatePlugin {
|
|
368
335
|
(source, chunk, hash) => {
|
369
336
|
if (needChunkLoadingCode(chunk)) {
|
370
337
|
const withDefer = needEntryDeferringCode(chunk);
|
338
|
+
const withPrefetch = needPrefetchingCode(chunk);
|
371
339
|
return Template.asString([
|
372
340
|
source,
|
373
341
|
"",
|
@@ -377,6 +345,7 @@ class JsonpMainTemplatePlugin {
|
|
377
345
|
"var chunkIds = data[0];",
|
378
346
|
"var moreModules = data[1];",
|
379
347
|
withDefer ? "var executeModules = data[2];" : "",
|
348
|
+
withPrefetch ? "var prefetchChunks = data[3] || [];" : "",
|
380
349
|
'// add "moreModules" to the modules object,',
|
381
350
|
'// then flag all "chunkIds" as loaded and fire callback',
|
382
351
|
"var moduleId, chunkId, i = 0, resolves = [];",
|
@@ -404,6 +373,23 @@ class JsonpMainTemplatePlugin {
|
|
404
373
|
]),
|
405
374
|
"}",
|
406
375
|
"if(parentJsonpFunction) parentJsonpFunction(data);",
|
376
|
+
withPrefetch
|
377
|
+
? Template.asString([
|
378
|
+
"// chunk prefetching for javascript",
|
379
|
+
"var head = document.getElementsByTagName('head')[0];",
|
380
|
+
"prefetchChunks.forEach(function(chunkId) {",
|
381
|
+
Template.indent([
|
382
|
+
"if(installedChunks[chunkId] === undefined) {",
|
383
|
+
Template.indent([
|
384
|
+
"installedChunks[chunkId] = null;",
|
385
|
+
mainTemplate.hooks.linkPrefetch.call("", chunk, hash),
|
386
|
+
"head.appendChild(link);"
|
387
|
+
]),
|
388
|
+
"}"
|
389
|
+
]),
|
390
|
+
"});"
|
391
|
+
])
|
392
|
+
: "",
|
407
393
|
"while(resolves.length) {",
|
408
394
|
Template.indent("resolves.shift()();"),
|
409
395
|
"}",
|
@@ -478,6 +464,25 @@ class JsonpMainTemplatePlugin {
|
|
478
464
|
return source;
|
479
465
|
}
|
480
466
|
);
|
467
|
+
mainTemplate.hooks.beforeStartup.tap(
|
468
|
+
"JsonpMainTemplatePlugin",
|
469
|
+
(source, chunk, hash) => {
|
470
|
+
const prefetchChunks = chunk.getChildIdsByOrders().prefetch;
|
471
|
+
if (
|
472
|
+
needChunkLoadingCode(chunk) &&
|
473
|
+
prefetchChunks &&
|
474
|
+
prefetchChunks.length
|
475
|
+
) {
|
476
|
+
return Template.asString([
|
477
|
+
source,
|
478
|
+
`webpackJsonpCallback([[], {}, 0, ${JSON.stringify(
|
479
|
+
prefetchChunks
|
480
|
+
)}]);`
|
481
|
+
]);
|
482
|
+
}
|
483
|
+
return source;
|
484
|
+
}
|
485
|
+
);
|
481
486
|
mainTemplate.hooks.startup.tap(
|
482
487
|
"JsonpMainTemplatePlugin",
|
483
488
|
(source, chunk, hash) => {
|
package/lib/webpack.js
CHANGED
@@ -44,8 +44,9 @@ const webpack = (options, callback) => {
|
|
44
44
|
throw new Error("Invalid argument: options");
|
45
45
|
}
|
46
46
|
if (callback) {
|
47
|
-
if (typeof callback !== "function")
|
47
|
+
if (typeof callback !== "function") {
|
48
48
|
throw new Error("Invalid argument: callback");
|
49
|
+
}
|
49
50
|
if (
|
50
51
|
options.watch === true ||
|
51
52
|
(Array.isArray(options) && options.some(o => o.watch))
|
@@ -19,8 +19,9 @@ module.exports = function() {
|
|
19
19
|
function hotDownloadManifest(requestTimeout) {
|
20
20
|
requestTimeout = requestTimeout || 10000;
|
21
21
|
return new Promise(function(resolve, reject) {
|
22
|
-
if (typeof XMLHttpRequest === "undefined")
|
22
|
+
if (typeof XMLHttpRequest === "undefined") {
|
23
23
|
return reject(new Error("No browser support"));
|
24
|
+
}
|
24
25
|
try {
|
25
26
|
var request = new XMLHttpRequest();
|
26
27
|
var requestPath = $require$.p + $hotMainFilename$;
|
package/package.json
CHANGED
@@ -1,19 +1,20 @@
|
|
1
1
|
{
|
2
2
|
"name": "webpack",
|
3
|
-
"version": "4.
|
3
|
+
"version": "4.12.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",
|
7
7
|
"dependencies": {
|
8
|
-
"@webassemblyjs/ast": "1.5.
|
9
|
-
"@webassemblyjs/
|
10
|
-
"@webassemblyjs/wasm-
|
11
|
-
"@webassemblyjs/wasm-
|
12
|
-
"
|
8
|
+
"@webassemblyjs/ast": "1.5.12",
|
9
|
+
"@webassemblyjs/helper-module-context": "1.5.12",
|
10
|
+
"@webassemblyjs/wasm-edit": "1.5.12",
|
11
|
+
"@webassemblyjs/wasm-opt": "1.5.12",
|
12
|
+
"@webassemblyjs/wasm-parser": "1.5.12",
|
13
|
+
"acorn": "^5.6.2",
|
13
14
|
"acorn-dynamic-import": "^3.0.0",
|
14
15
|
"ajv": "^6.1.0",
|
15
16
|
"ajv-keywords": "^3.1.0",
|
16
|
-
"chrome-trace-event": "^0.
|
17
|
+
"chrome-trace-event": "^1.0.0",
|
17
18
|
"enhanced-resolve": "^4.0.0",
|
18
19
|
"eslint-scope": "^3.7.1",
|
19
20
|
"json-parse-better-errors": "^1.0.2",
|
@@ -43,7 +44,7 @@
|
|
43
44
|
"es6-promise-polyfill": "^1.1.1",
|
44
45
|
"eslint": "^4.19.1",
|
45
46
|
"eslint-config-prettier": "^2.9.0",
|
46
|
-
"eslint-plugin-jest": "21.
|
47
|
+
"eslint-plugin-jest": "^21.17.0",
|
47
48
|
"eslint-plugin-node": "^6.0.1",
|
48
49
|
"eslint-plugin-prettier": "^2.6.0",
|
49
50
|
"express": "~4.13.1",
|
@@ -53,13 +54,13 @@
|
|
53
54
|
"istanbul": "^0.4.5",
|
54
55
|
"jade": "^1.11.0",
|
55
56
|
"jade-loader": "~0.8.0",
|
56
|
-
"jest": "23.0.
|
57
|
-
"jest-silent-reporter": "0.0.
|
57
|
+
"jest": "^23.0.1",
|
58
|
+
"jest-silent-reporter": "^0.0.5",
|
58
59
|
"json-loader": "^0.5.7",
|
59
60
|
"less": "^2.5.1",
|
60
61
|
"less-loader": "^4.0.3",
|
61
62
|
"lodash": "^4.17.4",
|
62
|
-
"prettier": "^1.
|
63
|
+
"prettier": "^1.13.2",
|
63
64
|
"pug": "^2.0.3",
|
64
65
|
"pug-loader": "^2.4.0",
|
65
66
|
"raw-loader": "~0.5.0",
|
@@ -1542,6 +1542,14 @@
|
|
1542
1542
|
"description": "Avoid emitting assets when errors occur",
|
1543
1543
|
"type": "boolean"
|
1544
1544
|
},
|
1545
|
+
"checkWasmTypes": {
|
1546
|
+
"description": "Check for incompatible wasm types when importing/exporting from/to ESM",
|
1547
|
+
"type": "boolean"
|
1548
|
+
},
|
1549
|
+
"mangleWasmImports": {
|
1550
|
+
"description": "Reduce size of WASM by changing imports to shorter strings.",
|
1551
|
+
"type": "boolean"
|
1552
|
+
},
|
1545
1553
|
"namedModules": {
|
1546
1554
|
"description": "Use readable module identifiers for better debugging",
|
1547
1555
|
"type": "boolean"
|