webpack 4.13.0 → 4.16.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/bin/webpack.js +7 -2
- package/hot/dev-server.js +2 -2
- package/hot/only-dev-server.js +2 -2
- package/hot/poll.js +5 -2
- package/hot/signal.js +2 -2
- package/lib/AsyncDependenciesBlock.js +44 -0
- package/lib/AutomaticPrefetchPlugin.js +2 -2
- package/lib/Chunk.js +56 -6
- package/lib/ChunkGroup.js +2 -2
- package/lib/ChunkTemplate.js +14 -2
- package/lib/CommentCompilationWarning.js +3 -3
- package/lib/CompatibilityPlugin.js +1 -1
- package/lib/Compilation.js +494 -36
- package/lib/Compiler.js +57 -4
- package/lib/ContextModule.js +23 -16
- package/lib/DelegatedModule.js +9 -1
- package/lib/DelegatedModuleFactoryPlugin.js +7 -1
- package/lib/DependenciesBlock.js +36 -3
- package/lib/DependenciesBlockVariable.js +22 -0
- package/lib/Dependency.js +33 -6
- package/lib/DllEntryPlugin.js +4 -1
- package/lib/DynamicEntryPlugin.js +21 -1
- package/lib/EntryOptionPlugin.js +12 -0
- package/lib/Entrypoint.js +1 -1
- package/lib/EnvironmentPlugin.js +8 -1
- package/lib/ExtendedAPIPlugin.js +8 -4
- package/lib/ExternalModuleFactoryPlugin.js +1 -1
- package/lib/FlagDependencyUsagePlugin.js +18 -13
- package/lib/Generator.js +1 -1
- package/lib/GraphHelpers.js +2 -1
- package/lib/HotModuleReplacement.runtime.js +8 -5
- package/lib/HotModuleReplacementPlugin.js +115 -117
- package/lib/IgnorePlugin.js +1 -1
- package/lib/MainTemplate.js +19 -4
- package/lib/Module.js +9 -3
- package/lib/ModuleReason.js +8 -0
- package/lib/MultiEntryPlugin.js +25 -3
- package/lib/NormalModule.js +5 -23
- package/lib/RuleSet.js +3 -3
- package/lib/RuntimeTemplate.js +4 -0
- package/lib/SingleEntryPlugin.js +20 -1
- package/lib/Stats.js +12 -5
- package/lib/Template.js +4 -1
- package/lib/UmdMainTemplatePlugin.js +12 -12
- package/lib/UseStrictPlugin.js +1 -1
- package/lib/WebpackError.js +4 -0
- package/lib/WebpackOptionsApply.js +92 -10
- package/lib/WebpackOptionsDefaulter.js +23 -6
- package/lib/WebpackOptionsValidationError.js +0 -1
- package/lib/compareLocations.js +13 -17
- package/lib/debug/ProfilingPlugin.js +5 -7
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +4 -6
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +0 -2
- package/lib/dependencies/DependencyReference.js +4 -0
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +18 -8
- package/lib/dependencies/LoaderDependency.js +3 -0
- package/lib/dependencies/LoaderPlugin.js +21 -2
- package/lib/dependencies/ModuleDependency.js +3 -0
- package/lib/dependencies/MultiEntryDependency.js +5 -0
- package/lib/dependencies/SingleEntryDependency.js +3 -0
- package/lib/dependencies/SystemPlugin.js +1 -1
- package/lib/formatLocation.js +55 -41
- package/lib/node/NodeMainTemplateAsync.runtime.js +1 -1
- package/lib/node/NodeMainTemplatePlugin.js +2 -2
- package/lib/node/NodeSourcePlugin.js +1 -1
- package/lib/optimize/ConcatenatedModule.js +24 -8
- package/lib/optimize/ModuleConcatenationPlugin.js +29 -14
- package/lib/optimize/NaturalChunkOrderPlugin.js +41 -0
- package/lib/optimize/OccurrenceChunkOrderPlugin.js +61 -0
- package/lib/optimize/OccurrenceModuleOrderPlugin.js +103 -0
- package/lib/optimize/OccurrenceOrderPlugin.js +2 -0
- package/lib/optimize/SplitChunksPlugin.js +168 -18
- package/lib/util/Semaphore.js +12 -0
- package/lib/util/SetHelpers.js +4 -4
- package/lib/util/SortableSet.js +1 -1
- package/lib/util/cachedMerge.js +1 -1
- package/lib/util/createHash.js +15 -0
- package/lib/util/deterministicGrouping.js +251 -0
- package/lib/util/identifier.js +27 -0
- package/lib/wasm/WasmFinalizeExportsPlugin.js +5 -2
- package/lib/wasm/WasmMainTemplatePlugin.js +10 -4
- package/lib/wasm/WebAssemblyGenerator.js +12 -12
- package/lib/wasm/WebAssemblyInInitialChunkError.js +88 -0
- package/lib/wasm/WebAssemblyModulesPlugin.js +28 -0
- package/lib/web/JsonpMainTemplatePlugin.js +1 -1
- package/lib/web/WebEnvironmentPlugin.js +18 -18
- package/lib/webpack.js +7 -0
- package/lib/webpack.web.js +2 -2
- package/lib/webworker/WebWorkerMainTemplatePlugin.js +1 -1
- package/package.json +21 -11
- package/schemas/WebpackOptions.json +70 -4
- package/schemas/plugins/optimize/OccurrenceOrderChunkIdsPlugin.json +10 -0
- package/schemas/plugins/optimize/OccurrenceOrderModuleIdsPlugin.json +10 -0
package/lib/Compiler.js
CHANGED
@@ -27,38 +27,83 @@ const RequestShortener = require("./RequestShortener");
|
|
27
27
|
const { makePathsRelative } = require("./util/identifier");
|
28
28
|
const ConcurrentCompilationError = require("./ConcurrentCompilationError");
|
29
29
|
|
30
|
+
/**
|
31
|
+
* @typedef {Object} CompilationParams
|
32
|
+
* @property {NormalModuleFactory} normalModuleFactory
|
33
|
+
* @property {ContextModuleFactory} contextModuleFactory
|
34
|
+
* @property {Set<string>} compilationDependencies
|
35
|
+
*/
|
36
|
+
|
37
|
+
/** @typedef {string|string[]} EntryValues */
|
38
|
+
/** @typedef {Record<string, EntryValues>} EntryOptionValues */
|
39
|
+
|
40
|
+
/**
|
41
|
+
* @callback EntryOptionValuesFunction
|
42
|
+
* @returns {EntryOptionValues | EntryValues} the computed value
|
43
|
+
*/
|
44
|
+
|
45
|
+
/** @typedef {EntryOptionValuesFunction | EntryOptionValues | EntryValues} EntryOptions */
|
46
|
+
|
30
47
|
class Compiler extends Tapable {
|
31
48
|
constructor(context) {
|
32
49
|
super();
|
33
50
|
this.hooks = {
|
51
|
+
/** @type {SyncBailHook<Compilation>} */
|
34
52
|
shouldEmit: new SyncBailHook(["compilation"]),
|
53
|
+
/** @type {AsyncSeriesHook<Stats>} */
|
35
54
|
done: new AsyncSeriesHook(["stats"]),
|
55
|
+
/** @type {AsyncSeriesHook<>} */
|
36
56
|
additionalPass: new AsyncSeriesHook([]),
|
37
|
-
|
38
|
-
|
57
|
+
/** @type {AsyncSeriesHook<Compiler>} */
|
58
|
+
beforeRun: new AsyncSeriesHook(["compiler"]),
|
59
|
+
/** @type {AsyncSeriesHook<Compiler>} */
|
60
|
+
run: new AsyncSeriesHook(["compiler"]),
|
61
|
+
/** @type {AsyncSeriesHook<Compilation>} */
|
39
62
|
emit: new AsyncSeriesHook(["compilation"]),
|
63
|
+
/** @type {AsyncSeriesHook<Compilation>} */
|
40
64
|
afterEmit: new AsyncSeriesHook(["compilation"]),
|
65
|
+
|
66
|
+
/** @type {SyncHook<Compilation, CompilationParams>} */
|
41
67
|
thisCompilation: new SyncHook(["compilation", "params"]),
|
68
|
+
/** @type {SyncHook<Compilation, CompilationParams>} */
|
42
69
|
compilation: new SyncHook(["compilation", "params"]),
|
70
|
+
/** @type {SyncHook<NormalModuleFactory>} */
|
43
71
|
normalModuleFactory: new SyncHook(["normalModuleFactory"]),
|
72
|
+
/** @type {SyncHook<ContextModuleFactory>} */
|
44
73
|
contextModuleFactory: new SyncHook(["contextModulefactory"]),
|
74
|
+
|
75
|
+
/** @type {AsyncSeriesHook<CompilationParams>} */
|
45
76
|
beforeCompile: new AsyncSeriesHook(["params"]),
|
77
|
+
/** @type {SyncHook<CompilationParams>} */
|
46
78
|
compile: new SyncHook(["params"]),
|
79
|
+
/** @type {AsyncParallelHook<Compilation>} */
|
47
80
|
make: new AsyncParallelHook(["compilation"]),
|
81
|
+
/** @type {AsyncSeriesHook<Compilation>} */
|
48
82
|
afterCompile: new AsyncSeriesHook(["compilation"]),
|
83
|
+
|
84
|
+
/** @type {AsyncSeriesHook<Compiler>} */
|
49
85
|
watchRun: new AsyncSeriesHook(["compiler"]),
|
86
|
+
/** @type {SyncHook<Error>} */
|
50
87
|
failed: new SyncHook(["error"]),
|
88
|
+
/** @type {SyncHook<string, string>} */
|
51
89
|
invalid: new SyncHook(["filename", "changeTime"]),
|
90
|
+
/** @type {SyncHook} */
|
52
91
|
watchClose: new SyncHook([]),
|
53
92
|
|
54
93
|
// TODO the following hooks are weirdly located here
|
55
94
|
// TODO move them for webpack 5
|
95
|
+
/** @type {SyncHook} */
|
56
96
|
environment: new SyncHook([]),
|
97
|
+
/** @type {SyncHook} */
|
57
98
|
afterEnvironment: new SyncHook([]),
|
99
|
+
/** @type {SyncHook<Compiler>} */
|
58
100
|
afterPlugins: new SyncHook(["compiler"]),
|
101
|
+
/** @type {SyncHook<Compiler>} */
|
59
102
|
afterResolvers: new SyncHook(["compiler"]),
|
103
|
+
/** @type {SyncBailHook<string, EntryOptions>} */
|
60
104
|
entryOption: new SyncBailHook(["context", "entry"])
|
61
105
|
};
|
106
|
+
|
62
107
|
this._pluginCompat.tap("Compiler", options => {
|
63
108
|
switch (options.name) {
|
64
109
|
case "additional-pass":
|
@@ -75,19 +120,26 @@ class Compiler extends Tapable {
|
|
75
120
|
}
|
76
121
|
});
|
77
122
|
|
123
|
+
/** @type {string=} */
|
78
124
|
this.name = undefined;
|
125
|
+
/** @type {Compilation=} */
|
79
126
|
this.parentCompilation = undefined;
|
127
|
+
/** @type {string} */
|
80
128
|
this.outputPath = "";
|
129
|
+
|
81
130
|
this.outputFileSystem = null;
|
82
131
|
this.inputFileSystem = null;
|
83
132
|
|
133
|
+
/** @type {string|null} */
|
84
134
|
this.recordsInputPath = null;
|
135
|
+
/** @type {string|null} */
|
85
136
|
this.recordsOutputPath = null;
|
86
137
|
this.records = {};
|
87
|
-
|
138
|
+
/** @type {Map<string, number>} */
|
88
139
|
this.fileTimestamps = new Map();
|
140
|
+
/** @type {Map<string, number>} */
|
89
141
|
this.contextTimestamps = new Map();
|
90
|
-
|
142
|
+
/** @type {ResolverFactory} */
|
91
143
|
this.resolverFactory = new ResolverFactory();
|
92
144
|
|
93
145
|
// TODO remove in webpack 5
|
@@ -136,6 +188,7 @@ class Compiler extends Tapable {
|
|
136
188
|
|
137
189
|
this.requestShortener = new RequestShortener(context);
|
138
190
|
|
191
|
+
/** @type {boolean} */
|
139
192
|
this.running = false;
|
140
193
|
}
|
141
194
|
|
package/lib/ContextModule.js
CHANGED
@@ -3,20 +3,37 @@
|
|
3
3
|
Author Tobias Koppers @sokra
|
4
4
|
*/
|
5
5
|
"use strict";
|
6
|
-
const path = require("path");
|
7
6
|
const util = require("util");
|
8
7
|
const { OriginalSource, RawSource } = require("webpack-sources");
|
9
8
|
const Module = require("./Module");
|
10
9
|
const AsyncDependenciesBlock = require("./AsyncDependenciesBlock");
|
11
10
|
const Template = require("./Template");
|
11
|
+
const contextify = require("./util/identifier").contextify;
|
12
12
|
|
13
13
|
/** @typedef {import("./dependencies/ContextElementDependency")} ContextElementDependency */
|
14
14
|
|
15
|
+
/**
|
16
|
+
* @callback ResolveDependenciesCallback
|
17
|
+
* @param {Error=} err
|
18
|
+
* @param {ContextElementDependency[]} dependencies
|
19
|
+
*/
|
20
|
+
|
21
|
+
/**
|
22
|
+
* @callback ResolveDependencies
|
23
|
+
* @param {TODO} fs
|
24
|
+
* @param {TODO} options
|
25
|
+
* @param {ResolveDependenciesCallback} callback
|
26
|
+
*/
|
27
|
+
|
15
28
|
class ContextModule extends Module {
|
16
29
|
// type ContextMode = "sync" | "eager" | "weak" | "async-weak" | "lazy" | "lazy-once"
|
17
30
|
// type ContextOptions = { resource: string, recursive: boolean, regExp: RegExp, addon?: string, mode?: ContextMode, chunkName?: string, include?: RegExp, exclude?: RegExp, groupOptions?: Object }
|
18
31
|
// resolveDependencies: (fs: FS, options: ContextOptions, (err: Error?, dependencies: Dependency[]) => void) => void
|
19
32
|
// options: ContextOptions
|
33
|
+
/**
|
34
|
+
* @param {ResolveDependencies} resolveDependencies function to get dependencies in this context
|
35
|
+
* @param {TODO} options options object
|
36
|
+
*/
|
20
37
|
constructor(resolveDependencies, options) {
|
21
38
|
let resource;
|
22
39
|
let resourceQuery;
|
@@ -63,18 +80,6 @@ class ContextModule extends Module {
|
|
63
80
|
return regexString.substring(1, regexString.length - 1);
|
64
81
|
}
|
65
82
|
|
66
|
-
contextify(context, request) {
|
67
|
-
return request
|
68
|
-
.split("!")
|
69
|
-
.map(subrequest => {
|
70
|
-
let rp = path.relative(context, subrequest);
|
71
|
-
if (path.sep === "\\") rp = rp.replace(/\\/g, "/");
|
72
|
-
if (rp.indexOf("../") !== 0) rp = "./" + rp;
|
73
|
-
return rp;
|
74
|
-
})
|
75
|
-
.join("!");
|
76
|
-
}
|
77
|
-
|
78
83
|
_createIdentifier() {
|
79
84
|
let identifier = this.context;
|
80
85
|
if (this.options.resourceQuery) {
|
@@ -155,7 +160,7 @@ class ContextModule extends Module {
|
|
155
160
|
}
|
156
161
|
|
157
162
|
libIdent(options) {
|
158
|
-
let identifier =
|
163
|
+
let identifier = contextify(options.context, this.context);
|
159
164
|
if (this.options.mode) {
|
160
165
|
identifier += ` ${this.options.mode}`;
|
161
166
|
}
|
@@ -163,7 +168,7 @@ class ContextModule extends Module {
|
|
163
168
|
identifier += " recursive";
|
164
169
|
}
|
165
170
|
if (this.options.addon) {
|
166
|
-
identifier += ` ${
|
171
|
+
identifier += ` ${contextify(options.context, this.options.addon)}`;
|
167
172
|
}
|
168
173
|
if (this.options.regExp) {
|
169
174
|
identifier += ` ${this.prettyRegExp(this.options.regExp + "")}`;
|
@@ -206,7 +211,9 @@ class ContextModule extends Module {
|
|
206
211
|
|
207
212
|
// enhance dependencies with meta info
|
208
213
|
for (const dep of dependencies) {
|
209
|
-
dep.loc =
|
214
|
+
dep.loc = {
|
215
|
+
name: dep.userRequest
|
216
|
+
};
|
210
217
|
dep.request = this.options.addon + dep.request;
|
211
218
|
}
|
212
219
|
|
package/lib/DelegatedModule.js
CHANGED
@@ -11,6 +11,8 @@ const WebpackMissingModule = require("./dependencies/WebpackMissingModule");
|
|
11
11
|
const DelegatedSourceDependency = require("./dependencies/DelegatedSourceDependency");
|
12
12
|
const DelegatedExportsDependency = require("./dependencies/DelegatedExportsDependency");
|
13
13
|
|
14
|
+
/** @typedef {import("./dependencies/ModuleDependency")} ModuleDependency */
|
15
|
+
|
14
16
|
class DelegatedModule extends Module {
|
15
17
|
constructor(sourceRequest, data, type, userRequest, originalRequest) {
|
16
18
|
super("javascript/dynamic", null);
|
@@ -22,6 +24,9 @@ class DelegatedModule extends Module {
|
|
22
24
|
this.userRequest = userRequest;
|
23
25
|
this.originalRequest = originalRequest;
|
24
26
|
this.delegateData = data;
|
27
|
+
|
28
|
+
// Build info
|
29
|
+
this.delegatedSourceDependency = undefined;
|
25
30
|
}
|
26
31
|
|
27
32
|
libIdent(options) {
|
@@ -48,7 +53,10 @@ class DelegatedModule extends Module {
|
|
48
53
|
this.built = true;
|
49
54
|
this.buildMeta = Object.assign({}, this.delegateData.buildMeta);
|
50
55
|
this.buildInfo = {};
|
51
|
-
this.
|
56
|
+
this.delegatedSourceDependency = new DelegatedSourceDependency(
|
57
|
+
this.sourceRequest
|
58
|
+
);
|
59
|
+
this.addDependency(this.delegatedSourceDependency);
|
52
60
|
this.addDependency(
|
53
61
|
new DelegatedExportsDependency(this, this.delegateData.exports || true)
|
54
62
|
);
|
@@ -15,7 +15,13 @@ class DelegatedModuleFactoryPlugin {
|
|
15
15
|
constructor(options) {
|
16
16
|
this.options = options;
|
17
17
|
options.type = options.type || "require";
|
18
|
-
options.extensions = options.extensions || [
|
18
|
+
options.extensions = options.extensions || [
|
19
|
+
"",
|
20
|
+
".wasm",
|
21
|
+
".mjs",
|
22
|
+
".js",
|
23
|
+
".json"
|
24
|
+
];
|
19
25
|
}
|
20
26
|
|
21
27
|
apply(normalModuleFactory) {
|
package/lib/DependenciesBlock.js
CHANGED
@@ -8,23 +8,39 @@ const DependenciesBlockVariable = require("./DependenciesBlockVariable");
|
|
8
8
|
|
9
9
|
/** @typedef {import("./ChunkGroup")} ChunkGroup */
|
10
10
|
/** @typedef {import("./Dependency")} Dependency */
|
11
|
+
/** @typedef {import("./AsyncDependenciesBlock")} AsyncDependenciesBlock */
|
12
|
+
/** @typedef {import("./DependenciesBlockVariable")} DependenciesBlockVariable */
|
13
|
+
/** @typedef {(d: Dependency) => boolean} DependencyFilterFunction */
|
14
|
+
/** @typedef {import("./util/createHash").Hash} Hash */
|
11
15
|
|
12
16
|
class DependenciesBlock {
|
13
17
|
constructor() {
|
14
18
|
/** @type {Dependency[]} */
|
15
19
|
this.dependencies = [];
|
20
|
+
/** @type {AsyncDependenciesBlock[]} */
|
16
21
|
this.blocks = [];
|
22
|
+
/** @type {DependenciesBlockVariable[]} */
|
17
23
|
this.variables = [];
|
18
|
-
// TODO remove this line, it's wrong
|
19
|
-
/** @type {ChunkGroup=} */
|
20
|
-
this.chunkGroup = undefined;
|
21
24
|
}
|
22
25
|
|
26
|
+
/**
|
27
|
+
* Adds a DependencyBlock to DependencyBlock relationship.
|
28
|
+
* This is used for when a Module has a AsyncDependencyBlock tie (for code-splitting)
|
29
|
+
*
|
30
|
+
* @param {AsyncDependenciesBlock} block block being added
|
31
|
+
* @returns {void}
|
32
|
+
*/
|
23
33
|
addBlock(block) {
|
24
34
|
this.blocks.push(block);
|
25
35
|
block.parent = this;
|
26
36
|
}
|
27
37
|
|
38
|
+
/**
|
39
|
+
* @param {string} name name of dependency
|
40
|
+
* @param {string} expression expression string for variable
|
41
|
+
* @param {Dependency[]} dependencies dependency instances tied to variable
|
42
|
+
* @returns {void}
|
43
|
+
*/
|
28
44
|
addVariable(name, expression, dependencies) {
|
29
45
|
for (let v of this.variables) {
|
30
46
|
if (v.name === name && v.expression === expression) {
|
@@ -36,10 +52,19 @@ class DependenciesBlock {
|
|
36
52
|
);
|
37
53
|
}
|
38
54
|
|
55
|
+
/**
|
56
|
+
* @param {Dependency} dependency dependency being tied to block.
|
57
|
+
* This is an "edge" pointing to another "node" on module graph.
|
58
|
+
* @returns {void}
|
59
|
+
*/
|
39
60
|
addDependency(dependency) {
|
40
61
|
this.dependencies.push(dependency);
|
41
62
|
}
|
42
63
|
|
64
|
+
/**
|
65
|
+
* @param {Dependency} dependency dependency being removed
|
66
|
+
* @returns {void}
|
67
|
+
*/
|
43
68
|
removeDependency(dependency) {
|
44
69
|
const idx = this.dependencies.indexOf(dependency);
|
45
70
|
if (idx >= 0) {
|
@@ -47,6 +72,10 @@ class DependenciesBlock {
|
|
47
72
|
}
|
48
73
|
}
|
49
74
|
|
75
|
+
/**
|
76
|
+
* @param {Hash} hash the hash used to track dependencies, from "crypto" module
|
77
|
+
* @returns {void}
|
78
|
+
*/
|
50
79
|
updateHash(hash) {
|
51
80
|
for (const dep of this.dependencies) dep.updateHash(hash);
|
52
81
|
for (const block of this.blocks) block.updateHash(hash);
|
@@ -63,6 +92,10 @@ class DependenciesBlock {
|
|
63
92
|
for (const block of this.blocks) block.unseal();
|
64
93
|
}
|
65
94
|
|
95
|
+
/**
|
96
|
+
* @param {DependencyFilterFunction} filter filter function for dependencies, gets passed all dependency ties from current instance
|
97
|
+
* @returns {boolean} returns boolean for filter
|
98
|
+
*/
|
66
99
|
hasDependencies(filter) {
|
67
100
|
if (filter) {
|
68
101
|
for (const dep of this.dependencies) {
|
@@ -6,13 +6,30 @@
|
|
6
6
|
|
7
7
|
const { RawSource, ReplaceSource } = require("webpack-sources");
|
8
8
|
|
9
|
+
/** @typedef {import("./Dependency")} Dependency */
|
10
|
+
/** @typedef {import("./Dependency").DependencyTemplate} DependencyTemplate */
|
11
|
+
/** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
|
12
|
+
/** @typedef {import("./util/createHash").Hash} Hash */
|
13
|
+
/** @typedef {(d: Dependency) => boolean} DependencyFilterFunction */
|
14
|
+
/** @typedef {Map<Function, DependencyTemplate>} DependencyTemplates */
|
15
|
+
|
9
16
|
class DependenciesBlockVariable {
|
17
|
+
/**
|
18
|
+
* Creates an instance of DependenciesBlockVariable.
|
19
|
+
* @param {string} name name of DependenciesBlockVariable
|
20
|
+
* @param {string} expression expression string
|
21
|
+
* @param {Dependency[]=} dependencies dependencies tied to this varaiable
|
22
|
+
*/
|
10
23
|
constructor(name, expression, dependencies) {
|
11
24
|
this.name = name;
|
12
25
|
this.expression = expression;
|
13
26
|
this.dependencies = dependencies || [];
|
14
27
|
}
|
15
28
|
|
29
|
+
/**
|
30
|
+
* @param {Hash} hash hash for instance to update
|
31
|
+
* @returns {void}
|
32
|
+
*/
|
16
33
|
updateHash(hash) {
|
17
34
|
hash.update(this.name);
|
18
35
|
hash.update(this.expression);
|
@@ -21,6 +38,11 @@ class DependenciesBlockVariable {
|
|
21
38
|
}
|
22
39
|
}
|
23
40
|
|
41
|
+
/**
|
42
|
+
* @param {DependencyTemplates} dependencyTemplates Dependency constructors and templates Map.
|
43
|
+
* @param {RuntimeTemplate} runtimeTemplate runtimeTemplate to generate expression souce
|
44
|
+
* @returns {ReplaceSource} returns constructed source for expression via templates
|
45
|
+
*/
|
24
46
|
expressionSource(dependencyTemplates, runtimeTemplate) {
|
25
47
|
const source = new ReplaceSource(new RawSource(this.expression));
|
26
48
|
for (const dep of this.dependencies) {
|
package/lib/Dependency.js
CHANGED
@@ -4,25 +4,47 @@
|
|
4
4
|
*/
|
5
5
|
"use strict";
|
6
6
|
|
7
|
+
const util = require("util");
|
7
8
|
const compareLocations = require("./compareLocations");
|
8
9
|
const DependencyReference = require("./dependencies/DependencyReference");
|
9
10
|
|
10
|
-
/** @typedef {
|
11
|
-
|
11
|
+
/** @typedef {import("./Module")} Module */
|
12
|
+
/** @typedef {import("webpack-sources").Source} Source */
|
13
|
+
/** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
|
14
|
+
|
15
|
+
/**
|
16
|
+
* @typedef {Object} DependencyTemplate
|
17
|
+
* @property {function(Dependency, Source, RuntimeTemplate, Map<Function, DependencyTemplate>): void} apply
|
18
|
+
*/
|
19
|
+
|
20
|
+
/** @typedef {Object} SourcePosition
|
12
21
|
* @property {number} line
|
22
|
+
* @property {number=} column
|
13
23
|
*/
|
14
24
|
|
15
|
-
/** @typedef {Object}
|
16
|
-
* @property {
|
17
|
-
* @property {
|
25
|
+
/** @typedef {Object} RealDependencyLocation
|
26
|
+
* @property {SourcePosition} start
|
27
|
+
* @property {SourcePosition=} end
|
28
|
+
* @property {number=} index
|
18
29
|
*/
|
19
30
|
|
31
|
+
/** @typedef {Object} SynteticDependencyLocation
|
32
|
+
* @property {string} name
|
33
|
+
* @property {number=} index
|
34
|
+
*/
|
35
|
+
|
36
|
+
/** @typedef {SynteticDependencyLocation|RealDependencyLocation} DependencyLocation */
|
37
|
+
|
20
38
|
class Dependency {
|
21
39
|
constructor() {
|
40
|
+
/** @type {Module|null} */
|
22
41
|
this.module = null;
|
23
42
|
// TODO remove in webpack 5
|
43
|
+
/** @type {boolean} */
|
24
44
|
this.weak = false;
|
45
|
+
/** @type {boolean} */
|
25
46
|
this.optional = false;
|
47
|
+
/** @type {DependencyLocation} */
|
26
48
|
this.loc = undefined;
|
27
49
|
}
|
28
50
|
|
@@ -57,6 +79,11 @@ class Dependency {
|
|
57
79
|
this.module = null;
|
58
80
|
}
|
59
81
|
}
|
60
|
-
|
82
|
+
|
83
|
+
// TODO remove in webpack 5
|
84
|
+
Dependency.compare = util.deprecate(
|
85
|
+
(a, b) => compareLocations(a.loc, b.loc),
|
86
|
+
"Dependency.compare is deprecated and will be removed in the next major version"
|
87
|
+
);
|
61
88
|
|
62
89
|
module.exports = Dependency;
|
package/lib/DllEntryPlugin.js
CHANGED
@@ -36,7 +36,10 @@ class DllEntryPlugin {
|
|
36
36
|
new DllEntryDependency(
|
37
37
|
this.entries.map((e, idx) => {
|
38
38
|
const dep = new SingleEntryDependency(e);
|
39
|
-
dep.loc =
|
39
|
+
dep.loc = {
|
40
|
+
name: this.name,
|
41
|
+
index: idx
|
42
|
+
};
|
40
43
|
return dep;
|
41
44
|
}),
|
42
45
|
this.name
|
@@ -10,12 +10,23 @@ const MultiModuleFactory = require("./MultiModuleFactory");
|
|
10
10
|
const MultiEntryPlugin = require("./MultiEntryPlugin");
|
11
11
|
const SingleEntryPlugin = require("./SingleEntryPlugin");
|
12
12
|
|
13
|
+
/** @typedef {import("./Compiler")} Compiler */
|
14
|
+
/** @typedef {import("./Compiler").EntryOptionValuesFunction} EntryOptionValuesFunction */
|
15
|
+
|
13
16
|
class DynamicEntryPlugin {
|
17
|
+
/**
|
18
|
+
* @param {string} context the context path
|
19
|
+
* @param {EntryOptionValuesFunction} entry the entry value
|
20
|
+
*/
|
14
21
|
constructor(context, entry) {
|
15
22
|
this.context = context;
|
16
23
|
this.entry = entry;
|
17
24
|
}
|
18
25
|
|
26
|
+
/**
|
27
|
+
* @param {Compiler} compiler the compiler instance
|
28
|
+
* @returns {void}
|
29
|
+
*/
|
19
30
|
apply(compiler) {
|
20
31
|
compiler.hooks.compilation.tap(
|
21
32
|
"DynamicEntryPlugin",
|
@@ -36,6 +47,11 @@ class DynamicEntryPlugin {
|
|
36
47
|
compiler.hooks.make.tapAsync(
|
37
48
|
"DynamicEntryPlugin",
|
38
49
|
(compilation, callback) => {
|
50
|
+
/**
|
51
|
+
* @param {string|string[]} entry entry value or array of entry values
|
52
|
+
* @param {string} name name of entry
|
53
|
+
* @returns {Promise<any>} returns the promise resolving the Compilation#addEntry function
|
54
|
+
*/
|
39
55
|
const addEntry = (entry, name) => {
|
40
56
|
const dep = DynamicEntryPlugin.createDependency(entry, name);
|
41
57
|
return new Promise((resolve, reject) => {
|
@@ -63,7 +79,11 @@ class DynamicEntryPlugin {
|
|
63
79
|
}
|
64
80
|
|
65
81
|
module.exports = DynamicEntryPlugin;
|
66
|
-
|
82
|
+
/**
|
83
|
+
* @param {string|string[]} entry entry value or array of entry paths
|
84
|
+
* @param {string} name name of entry
|
85
|
+
* @returns {SingleEntryDependency|MultiEntryDependency} returns dep
|
86
|
+
*/
|
67
87
|
DynamicEntryPlugin.createDependency = (entry, name) => {
|
68
88
|
if (Array.isArray(entry)) {
|
69
89
|
return MultiEntryPlugin.createDependency(entry, name);
|
package/lib/EntryOptionPlugin.js
CHANGED
@@ -8,6 +8,14 @@ const SingleEntryPlugin = require("./SingleEntryPlugin");
|
|
8
8
|
const MultiEntryPlugin = require("./MultiEntryPlugin");
|
9
9
|
const DynamicEntryPlugin = require("./DynamicEntryPlugin");
|
10
10
|
|
11
|
+
/** @typedef {import("./Compiler")} Compiler */
|
12
|
+
|
13
|
+
/**
|
14
|
+
* @param {string} context context path
|
15
|
+
* @param {string | string[]} item entry array or single path
|
16
|
+
* @param {string} name entry key name
|
17
|
+
* @returns {SingleEntryPlugin | MultiEntryPlugin} returns either a single or multi entry plugin
|
18
|
+
*/
|
11
19
|
const itemToPlugin = (context, item, name) => {
|
12
20
|
if (Array.isArray(item)) {
|
13
21
|
return new MultiEntryPlugin(context, item, name);
|
@@ -16,6 +24,10 @@ const itemToPlugin = (context, item, name) => {
|
|
16
24
|
};
|
17
25
|
|
18
26
|
module.exports = class EntryOptionPlugin {
|
27
|
+
/**
|
28
|
+
* @param {Compiler} compiler the compiler instance one is tapping into
|
29
|
+
* @returns {void}
|
30
|
+
*/
|
19
31
|
apply(compiler) {
|
20
32
|
compiler.hooks.entryOption.tap("EntryOptionPlugin", (context, entry) => {
|
21
33
|
if (typeof entry === "string" || Array.isArray(entry)) {
|
package/lib/Entrypoint.js
CHANGED
package/lib/EnvironmentPlugin.js
CHANGED
@@ -5,6 +5,9 @@
|
|
5
5
|
|
6
6
|
"use strict";
|
7
7
|
|
8
|
+
/** @typedef {import("./Compiler")} Compiler */
|
9
|
+
|
10
|
+
const WebpackError = require("./WebpackError");
|
8
11
|
const DefinePlugin = require("./DefinePlugin");
|
9
12
|
|
10
13
|
const needsEnvVarFix =
|
@@ -25,6 +28,10 @@ class EnvironmentPlugin {
|
|
25
28
|
}
|
26
29
|
}
|
27
30
|
|
31
|
+
/**
|
32
|
+
* @param {Compiler} compiler webpack compiler instance
|
33
|
+
* @returns {void}
|
34
|
+
*/
|
28
35
|
apply(compiler) {
|
29
36
|
const definitions = this.keys.reduce((defs, key) => {
|
30
37
|
// TODO remove once the fix has made its way into Node 8.
|
@@ -41,7 +48,7 @@ class EnvironmentPlugin {
|
|
41
48
|
|
42
49
|
if (value === undefined) {
|
43
50
|
compiler.hooks.thisCompilation.tap("EnvironmentPlugin", compilation => {
|
44
|
-
const error = new
|
51
|
+
const error = new WebpackError(
|
45
52
|
`EnvironmentPlugin - ${key} environment variable is undefined.\n\n` +
|
46
53
|
"You can pass an object with default values to suppress this warning.\n" +
|
47
54
|
"See https://webpack.js.org/plugins/environment-plugin for example."
|
package/lib/ExtendedAPIPlugin.js
CHANGED
@@ -10,12 +10,16 @@ const ParserHelpers = require("./ParserHelpers");
|
|
10
10
|
const NullFactory = require("./NullFactory");
|
11
11
|
|
12
12
|
const REPLACEMENTS = {
|
13
|
-
|
14
|
-
|
13
|
+
// eslint-disable-next-line camelcase
|
14
|
+
__webpack_hash__: "__webpack_require__.h",
|
15
|
+
// eslint-disable-next-line camelcase
|
16
|
+
__webpack_chunkname__: "__webpack_require__.cn"
|
15
17
|
};
|
16
18
|
const REPLACEMENT_TYPES = {
|
17
|
-
|
18
|
-
|
19
|
+
// eslint-disable-next-line camelcase
|
20
|
+
__webpack_hash__: "string",
|
21
|
+
// eslint-disable-next-line camelcase
|
22
|
+
__webpack_chunkname__: "string"
|
19
23
|
};
|
20
24
|
|
21
25
|
class ExtendedAPIPlugin {
|
@@ -64,7 +64,7 @@ class ExternalModuleFactoryPlugin {
|
|
64
64
|
asyncFlag = true;
|
65
65
|
if (i >= externals.length) return callback();
|
66
66
|
handleExternals(externals[i++], handleExternalsAndCallback);
|
67
|
-
} while (!asyncFlag);
|
67
|
+
} while (!asyncFlag);
|
68
68
|
asyncFlag = false;
|
69
69
|
};
|
70
70
|
|