webpack 4.19.0 → 4.20.2
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 +4 -0
- package/lib/AmdMainTemplatePlugin.js +5 -3
- package/lib/BannerPlugin.js +13 -5
- package/lib/Chunk.js +3 -0
- package/lib/Compilation.js +23 -18
- package/lib/Compiler.js +6 -12
- package/lib/DllPlugin.js +5 -0
- package/lib/DllReferencePlugin.js +70 -46
- package/lib/DynamicEntryPlugin.js +4 -3
- package/lib/EntryOptionPlugin.js +2 -1
- package/lib/ExternalModule.js +16 -4
- package/lib/HashedModuleIdsPlugin.js +9 -1
- package/lib/HotUpdateChunk.js +1 -0
- package/lib/IgnorePlugin.js +10 -14
- package/lib/LibraryTemplatePlugin.js +33 -10
- package/lib/LoaderOptionsPlugin.js +5 -0
- package/lib/Module.js +4 -0
- package/lib/SourceMapDevToolPlugin.js +16 -3
- package/lib/Template.js +1 -0
- package/lib/UmdMainTemplatePlugin.js +2 -1
- package/lib/WatchIgnorePlugin.js +5 -0
- package/lib/WebpackOptionsApply.js +18 -2
- package/lib/WebpackOptionsDefaulter.js +5 -1
- package/lib/debug/ProfilingPlugin.js +6 -0
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +16 -1
- package/lib/dependencies/HarmonyExportExpressionDependency.js +7 -2
- package/lib/dependencies/ImportParserPlugin.js +1 -1
- package/lib/dependencies/WebAssemblyImportDependency.js +9 -1
- package/lib/node/NodeMainTemplatePlugin.js +2 -2
- package/lib/optimize/AggressiveSplittingPlugin.js +9 -2
- package/lib/optimize/ConcatenatedModule.js +10 -2
- package/lib/optimize/LimitChunkCountPlugin.js +9 -2
- package/lib/optimize/MinChunkSizePlugin.js +5 -0
- package/lib/optimize/OccurrenceChunkOrderPlugin.js +5 -0
- package/lib/optimize/OccurrenceModuleOrderPlugin.js +5 -0
- package/lib/web/JsonpExportMainTemplatePlugin.js +3 -0
- package/lib/webpack.js +12 -1
- package/package.json +11 -8
- package/schemas/WebpackOptions.json +1293 -1113
- package/schemas/plugins/BannerPlugin.json +34 -27
- package/schemas/plugins/DllPlugin.json +18 -16
- package/schemas/plugins/DllReferencePlugin.json +180 -68
- package/schemas/plugins/HashedModuleIdsPlugin.json +9 -3
- package/schemas/plugins/IgnorePlugin.json +17 -11
- package/schemas/plugins/LoaderOptionsPlugin.json +27 -26
- package/schemas/plugins/SourceMapDevToolPlugin.json +87 -83
- package/schemas/plugins/WatchIgnorePlugin.json +18 -16
- package/schemas/plugins/debug/ProfilingPlugin.json +13 -12
- package/schemas/plugins/optimize/AggressiveSplittingPlugin.json +23 -22
- package/schemas/plugins/optimize/LimitChunkCountPlugin.json +16 -15
- package/schemas/plugins/optimize/MinChunkSizePlugin.json +4 -3
- package/schemas/plugins/optimize/OccurrenceOrderChunkIdsPlugin.json +2 -1
- package/schemas/plugins/optimize/OccurrenceOrderModuleIdsPlugin.json +2 -1
package/README.md
CHANGED
@@ -11,6 +11,7 @@
|
|
11
11
|
[![deps][deps]][deps-url]
|
12
12
|
[![tests][tests]][tests-url]
|
13
13
|
[![builds][builds]][builds-url]
|
14
|
+
[![builds2][builds2]][builds2-url]
|
14
15
|
[![coverage][cover]][cover-url]
|
15
16
|
[![licenses][licenses]][licenses-url]
|
16
17
|
|
@@ -752,6 +753,9 @@ src="https://static.monei.net/monei-logo.svg" height="30" alt="MONEI"></a>
|
|
752
753
|
[builds-url]: https://ci.appveyor.com/project/sokra/webpack/branch/master
|
753
754
|
[builds]: https://ci.appveyor.com/api/projects/status/github/webpack/webpack?svg=true
|
754
755
|
|
756
|
+
[builds2]: https://dev.azure.com/webpack/webpack/_apis/build/status/webpack.webpack
|
757
|
+
[builds2-url]: https://dev.azure.com/webpack/webpack/_build/latest?definitionId=3
|
758
|
+
|
755
759
|
[licenses-url]: https://app.fossa.io/projects/git%2Bhttps%3A%2F%2Fgithub.com%2Fwebpack%2Fwebpack?ref=badge_shield
|
756
760
|
[licenses]: https://app.fossa.io/api/projects/git%2Bhttps%3A%2F%2Fgithub.com%2Fwebpack%2Fwebpack.svg?type=shield
|
757
761
|
|
@@ -12,10 +12,10 @@ const Template = require("./Template");
|
|
12
12
|
|
13
13
|
class AmdMainTemplatePlugin {
|
14
14
|
/**
|
15
|
-
* @param {string} name the library name
|
15
|
+
* @param {string=} name the library name
|
16
16
|
*/
|
17
17
|
constructor(name) {
|
18
|
-
/** @type {string} */
|
18
|
+
/** @type {string=} */
|
19
19
|
this.name = name;
|
20
20
|
}
|
21
21
|
|
@@ -79,7 +79,9 @@ class AmdMainTemplatePlugin {
|
|
79
79
|
|
80
80
|
mainTemplate.hooks.hash.tap("AmdMainTemplatePlugin", hash => {
|
81
81
|
hash.update("exports amd");
|
82
|
-
|
82
|
+
if (this.name) {
|
83
|
+
hash.update(this.name);
|
84
|
+
}
|
83
85
|
});
|
84
86
|
}
|
85
87
|
}
|
package/lib/BannerPlugin.js
CHANGED
@@ -12,6 +12,9 @@ const Template = require("./Template");
|
|
12
12
|
const validateOptions = require("schema-utils");
|
13
13
|
const schema = require("../schemas/plugins/BannerPlugin.json");
|
14
14
|
|
15
|
+
/** @typedef {import("../declarations/plugins/BannerPlugin").BannerPluginArgument} BannerPluginArgument */
|
16
|
+
/** @typedef {import("../declarations/plugins/BannerPlugin").BannerPluginOptions} BannerPluginOptions */
|
17
|
+
|
15
18
|
const wrapComment = str => {
|
16
19
|
if (!str.includes("\n")) {
|
17
20
|
return Template.toComment(str);
|
@@ -23,6 +26,9 @@ const wrapComment = str => {
|
|
23
26
|
};
|
24
27
|
|
25
28
|
class BannerPlugin {
|
29
|
+
/**
|
30
|
+
* @param {BannerPluginArgument} options options object
|
31
|
+
*/
|
26
32
|
constructor(options) {
|
27
33
|
if (arguments.length > 1) {
|
28
34
|
throw new Error(
|
@@ -38,17 +44,19 @@ class BannerPlugin {
|
|
38
44
|
};
|
39
45
|
}
|
40
46
|
|
41
|
-
|
47
|
+
/** @type {BannerPluginOptions} */
|
48
|
+
this.options = options;
|
42
49
|
|
43
|
-
|
44
|
-
|
50
|
+
const bannerOption = options.banner;
|
51
|
+
if (typeof bannerOption === "function") {
|
52
|
+
const getBanner = bannerOption;
|
45
53
|
this.banner = this.options.raw
|
46
54
|
? getBanner
|
47
55
|
: data => wrapComment(getBanner(data));
|
48
56
|
} else {
|
49
57
|
const banner = this.options.raw
|
50
|
-
?
|
51
|
-
: wrapComment(
|
58
|
+
? bannerOption
|
59
|
+
: wrapComment(bannerOption);
|
52
60
|
this.banner = () => banner;
|
53
61
|
}
|
54
62
|
}
|
package/lib/Chunk.js
CHANGED
package/lib/Compilation.js
CHANGED
@@ -402,7 +402,8 @@ class Compilation extends Tapable {
|
|
402
402
|
this.inputFileSystem = compiler.inputFileSystem;
|
403
403
|
this.requestShortener = compiler.requestShortener;
|
404
404
|
|
405
|
-
const options =
|
405
|
+
const options = compiler.options;
|
406
|
+
this.options = options;
|
406
407
|
this.outputOptions = options && options.output;
|
407
408
|
/** @type {boolean=} */
|
408
409
|
this.bail = options && options.bail;
|
@@ -2253,24 +2254,28 @@ class Compilation extends Tapable {
|
|
2253
2254
|
for (let i = 0; i < chunks.length; i++) {
|
2254
2255
|
const chunk = chunks[i];
|
2255
2256
|
const chunkHash = createHash(hashFunction);
|
2256
|
-
|
2257
|
-
|
2257
|
+
try {
|
2258
|
+
if (outputOptions.hashSalt) {
|
2259
|
+
chunkHash.update(outputOptions.hashSalt);
|
2260
|
+
}
|
2261
|
+
chunk.updateHash(chunkHash);
|
2262
|
+
const template = chunk.hasRuntime()
|
2263
|
+
? this.mainTemplate
|
2264
|
+
: this.chunkTemplate;
|
2265
|
+
template.updateHashForChunk(
|
2266
|
+
chunkHash,
|
2267
|
+
chunk,
|
2268
|
+
this.moduleTemplates.javascript,
|
2269
|
+
this.dependencyTemplates
|
2270
|
+
);
|
2271
|
+
this.hooks.chunkHash.call(chunk, chunkHash);
|
2272
|
+
chunk.hash = chunkHash.digest(hashDigest);
|
2273
|
+
hash.update(chunk.hash);
|
2274
|
+
chunk.renderedHash = chunk.hash.substr(0, hashDigestLength);
|
2275
|
+
this.hooks.contentHash.call(chunk);
|
2276
|
+
} catch (err) {
|
2277
|
+
this.errors.push(new ChunkRenderError(chunk, "", err));
|
2258
2278
|
}
|
2259
|
-
chunk.updateHash(chunkHash);
|
2260
|
-
const template = chunk.hasRuntime()
|
2261
|
-
? this.mainTemplate
|
2262
|
-
: this.chunkTemplate;
|
2263
|
-
template.updateHashForChunk(
|
2264
|
-
chunkHash,
|
2265
|
-
chunk,
|
2266
|
-
this.moduleTemplates.javascript,
|
2267
|
-
this.dependencyTemplates
|
2268
|
-
);
|
2269
|
-
this.hooks.chunkHash.call(chunk, chunkHash);
|
2270
|
-
chunk.hash = chunkHash.digest(hashDigest);
|
2271
|
-
hash.update(chunk.hash);
|
2272
|
-
chunk.renderedHash = chunk.hash.substr(0, hashDigestLength);
|
2273
|
-
this.hooks.contentHash.call(chunk);
|
2274
2279
|
}
|
2275
2280
|
this.fullHash = hash.digest(hashDigest);
|
2276
2281
|
this.hash = this.fullHash.substr(0, hashDigestLength);
|
package/lib/Compiler.js
CHANGED
@@ -27,6 +27,9 @@ const RequestShortener = require("./RequestShortener");
|
|
27
27
|
const { makePathsRelative } = require("./util/identifier");
|
28
28
|
const ConcurrentCompilationError = require("./ConcurrentCompilationError");
|
29
29
|
|
30
|
+
/** @typedef {import("../declarations/WebpackOptions").Entry} Entry */
|
31
|
+
/** @typedef {import("../declarations/WebpackOptions").WebpackOptions} WebpackOptions */
|
32
|
+
|
30
33
|
/**
|
31
34
|
* @typedef {Object} CompilationParams
|
32
35
|
* @property {NormalModuleFactory} normalModuleFactory
|
@@ -34,16 +37,6 @@ const ConcurrentCompilationError = require("./ConcurrentCompilationError");
|
|
34
37
|
* @property {Set<string>} compilationDependencies
|
35
38
|
*/
|
36
39
|
|
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
|
-
|
47
40
|
class Compiler extends Tapable {
|
48
41
|
constructor(context) {
|
49
42
|
super();
|
@@ -100,7 +93,7 @@ class Compiler extends Tapable {
|
|
100
93
|
afterPlugins: new SyncHook(["compiler"]),
|
101
94
|
/** @type {SyncHook<Compiler>} */
|
102
95
|
afterResolvers: new SyncHook(["compiler"]),
|
103
|
-
/** @type {SyncBailHook<string,
|
96
|
+
/** @type {SyncBailHook<string, Entry>} */
|
104
97
|
entryOption: new SyncBailHook(["context", "entry"])
|
105
98
|
};
|
106
99
|
|
@@ -182,7 +175,8 @@ class Compiler extends Tapable {
|
|
182
175
|
}
|
183
176
|
};
|
184
177
|
|
185
|
-
|
178
|
+
/** @type {WebpackOptions} */
|
179
|
+
this.options = /** @type {WebpackOptions} */ ({});
|
186
180
|
|
187
181
|
this.context = context;
|
188
182
|
|
package/lib/DllPlugin.js
CHANGED
@@ -11,7 +11,12 @@ const FlagInitialModulesAsUsedPlugin = require("./FlagInitialModulesAsUsedPlugin
|
|
11
11
|
const validateOptions = require("schema-utils");
|
12
12
|
const schema = require("../schemas/plugins/DllPlugin.json");
|
13
13
|
|
14
|
+
/** @typedef {import("../declarations/plugins/DllPlugin").DllPluginOptions} DllPluginOptions */
|
15
|
+
|
14
16
|
class DllPlugin {
|
17
|
+
/**
|
18
|
+
* @param {DllPluginOptions} options options object
|
19
|
+
*/
|
15
20
|
constructor(options) {
|
16
21
|
validateOptions(schema, options, "Dll Plugin");
|
17
22
|
this.options = options;
|
@@ -16,7 +16,13 @@ const WebpackError = require("./WebpackError");
|
|
16
16
|
const validateOptions = require("schema-utils");
|
17
17
|
const schema = require("../schemas/plugins/DllReferencePlugin.json");
|
18
18
|
|
19
|
+
/** @typedef {import("../declarations/plugins/DllReferencePlugin").DllReferencePluginOptions} DllReferencePluginOptions */
|
20
|
+
/** @typedef {import("../declarations/plugins/DllReferencePlugin").DllReferencePluginOptionsManifest} DllReferencePluginOptionsManifest */
|
21
|
+
|
19
22
|
class DllReferencePlugin {
|
23
|
+
/**
|
24
|
+
* @param {DllReferencePluginOptions} options options object
|
25
|
+
*/
|
20
26
|
constructor(options) {
|
21
27
|
validateOptions(schema, options, "Dll Reference Plugin");
|
22
28
|
this.options = options;
|
@@ -40,55 +46,71 @@ class DllReferencePlugin {
|
|
40
46
|
compiler.hooks.beforeCompile.tapAsync(
|
41
47
|
"DllReferencePlugin",
|
42
48
|
(params, callback) => {
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
49
|
+
if ("manifest" in this.options) {
|
50
|
+
const manifest = this.options.manifest;
|
51
|
+
if (typeof manifest === "string") {
|
52
|
+
params.compilationDependencies.add(manifest);
|
53
|
+
compiler.inputFileSystem.readFile(manifest, (err, result) => {
|
54
|
+
if (err) return callback(err);
|
55
|
+
// Catch errors parsing the manifest so that blank
|
56
|
+
// or malformed manifest files don't kill the process.
|
57
|
+
try {
|
58
|
+
params["dll reference " + manifest] = parseJson(
|
59
|
+
result.toString("utf-8")
|
60
|
+
);
|
61
|
+
} catch (e) {
|
62
|
+
// Store the error in the params so that it can
|
63
|
+
// be added as a compilation error later on.
|
64
|
+
const manifestPath = makePathsRelative(
|
65
|
+
compiler.options.context,
|
66
|
+
manifest
|
67
|
+
);
|
68
|
+
params[
|
69
|
+
"dll reference parse error " + manifest
|
70
|
+
] = new DllManifestError(manifestPath, e.message);
|
71
|
+
}
|
72
|
+
return callback();
|
73
|
+
});
|
74
|
+
return;
|
75
|
+
}
|
69
76
|
}
|
77
|
+
return callback();
|
70
78
|
}
|
71
79
|
);
|
72
80
|
|
73
81
|
compiler.hooks.compile.tap("DllReferencePlugin", params => {
|
74
|
-
let
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
82
|
+
let name = this.options.name;
|
83
|
+
let sourceType = this.options.sourceType;
|
84
|
+
let content =
|
85
|
+
"content" in this.options ? this.options.content : undefined;
|
86
|
+
if ("manifest" in this.options) {
|
87
|
+
let manifestParameter = this.options.manifest;
|
88
|
+
let manifest;
|
89
|
+
if (typeof manifestParameter === "string") {
|
90
|
+
// If there was an error parsing the manifest
|
91
|
+
// file, exit now because the error will be added
|
92
|
+
// as a compilation error in the "compilation" hook.
|
93
|
+
if (params["dll reference parse error " + manifestParameter]) {
|
94
|
+
return;
|
95
|
+
}
|
96
|
+
manifest =
|
97
|
+
/** @type {DllReferencePluginOptionsManifest} */ (params[
|
98
|
+
"dll reference " + manifestParameter
|
99
|
+
]);
|
100
|
+
} else {
|
101
|
+
manifest = manifestParameter;
|
102
|
+
}
|
103
|
+
if (manifest) {
|
104
|
+
if (!name) name = manifest.name;
|
105
|
+
if (!sourceType) sourceType = manifest.type;
|
106
|
+
if (!content) content = manifest.content;
|
81
107
|
}
|
82
|
-
manifest = params["dll reference " + manifest];
|
83
108
|
}
|
84
|
-
const name = this.options.name || manifest.name;
|
85
|
-
const sourceType =
|
86
|
-
this.options.sourceType || (manifest && manifest.type) || "var";
|
87
109
|
const externals = {};
|
88
110
|
const source = "dll-reference " + name;
|
89
111
|
externals[source] = name;
|
90
112
|
const normalModuleFactory = params.normalModuleFactory;
|
91
|
-
new ExternalModuleFactoryPlugin(sourceType, externals).apply(
|
113
|
+
new ExternalModuleFactoryPlugin(sourceType || "var", externals).apply(
|
92
114
|
normalModuleFactory
|
93
115
|
);
|
94
116
|
new DelegatedModuleFactoryPlugin({
|
@@ -96,7 +118,7 @@ class DllReferencePlugin {
|
|
96
118
|
type: this.options.type,
|
97
119
|
scope: this.options.scope,
|
98
120
|
context: this.options.context || compiler.options.context,
|
99
|
-
content
|
121
|
+
content,
|
100
122
|
extensions: this.options.extensions
|
101
123
|
}).apply(normalModuleFactory);
|
102
124
|
});
|
@@ -104,13 +126,15 @@ class DllReferencePlugin {
|
|
104
126
|
compiler.hooks.compilation.tap(
|
105
127
|
"DllReferencePlugin",
|
106
128
|
(compilation, params) => {
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
129
|
+
if ("manifest" in this.options) {
|
130
|
+
let manifest = this.options.manifest;
|
131
|
+
if (typeof manifest === "string") {
|
132
|
+
// If there was an error parsing the manifest file, add the
|
133
|
+
// error as a compilation error to make the compilation fail.
|
134
|
+
let e = params["dll reference parse error " + manifest];
|
135
|
+
if (e) {
|
136
|
+
compilation.errors.push(e);
|
137
|
+
}
|
114
138
|
}
|
115
139
|
}
|
116
140
|
}
|
@@ -10,13 +10,14 @@ const MultiModuleFactory = require("./MultiModuleFactory");
|
|
10
10
|
const MultiEntryPlugin = require("./MultiEntryPlugin");
|
11
11
|
const SingleEntryPlugin = require("./SingleEntryPlugin");
|
12
12
|
|
13
|
+
/** @typedef {import("../declarations/WebpackOptions").EntryDynamic} EntryDynamic */
|
14
|
+
/** @typedef {import("../declarations/WebpackOptions").EntryStatic} EntryStatic */
|
13
15
|
/** @typedef {import("./Compiler")} Compiler */
|
14
|
-
/** @typedef {import("./Compiler").EntryOptionValuesFunction} EntryOptionValuesFunction */
|
15
16
|
|
16
17
|
class DynamicEntryPlugin {
|
17
18
|
/**
|
18
19
|
* @param {string} context the context path
|
19
|
-
* @param {
|
20
|
+
* @param {EntryDynamic} entry the entry value
|
20
21
|
*/
|
21
22
|
constructor(context, entry) {
|
22
23
|
this.context = context;
|
@@ -50,7 +51,7 @@ class DynamicEntryPlugin {
|
|
50
51
|
/**
|
51
52
|
* @param {string|string[]} entry entry value or array of entry values
|
52
53
|
* @param {string} name name of entry
|
53
|
-
* @returns {Promise<
|
54
|
+
* @returns {Promise<EntryStatic>} returns the promise resolving the Compilation#addEntry function
|
54
55
|
*/
|
55
56
|
const addEntry = (entry, name) => {
|
56
57
|
const dep = DynamicEntryPlugin.createDependency(entry, name);
|
package/lib/EntryOptionPlugin.js
CHANGED
@@ -8,11 +8,12 @@ const SingleEntryPlugin = require("./SingleEntryPlugin");
|
|
8
8
|
const MultiEntryPlugin = require("./MultiEntryPlugin");
|
9
9
|
const DynamicEntryPlugin = require("./DynamicEntryPlugin");
|
10
10
|
|
11
|
+
/** @typedef {import("../declarations/WebpackOptions").EntryItem} EntryItem */
|
11
12
|
/** @typedef {import("./Compiler")} Compiler */
|
12
13
|
|
13
14
|
/**
|
14
15
|
* @param {string} context context path
|
15
|
-
* @param {
|
16
|
+
* @param {EntryItem} item entry array or single path
|
16
17
|
* @param {string} name entry key name
|
17
18
|
* @returns {SingleEntryPlugin | MultiEntryPlugin} returns either a single or multi entry plugin
|
18
19
|
*/
|
package/lib/ExternalModule.js
CHANGED
@@ -74,7 +74,9 @@ class ExternalModule extends Module {
|
|
74
74
|
.slice(1)
|
75
75
|
.map(r => `[${JSON.stringify(r)}]`)
|
76
76
|
.join("");
|
77
|
-
return `module.exports = require(${
|
77
|
+
return `module.exports = require(${JSON.stringify(
|
78
|
+
moduleName
|
79
|
+
)})${objectLookup};`;
|
78
80
|
}
|
79
81
|
|
80
82
|
checkExternalVariable(variableToCheck, request) {
|
@@ -94,15 +96,25 @@ class ExternalModule extends Module {
|
|
94
96
|
}
|
95
97
|
|
96
98
|
getSourceForDefaultCase(optional, request) {
|
99
|
+
if (!Array.isArray(request)) {
|
100
|
+
// make it an array as the look up works the same basically
|
101
|
+
request = [request];
|
102
|
+
}
|
103
|
+
|
104
|
+
const variableName = request[0];
|
97
105
|
const missingModuleError = optional
|
98
|
-
? this.checkExternalVariable(
|
106
|
+
? this.checkExternalVariable(variableName, request.join("."))
|
99
107
|
: "";
|
100
|
-
|
108
|
+
const objectLookup = request
|
109
|
+
.slice(1)
|
110
|
+
.map(r => `[${JSON.stringify(r)}]`)
|
111
|
+
.join("");
|
112
|
+
return `${missingModuleError}module.exports = ${variableName}${objectLookup};`;
|
101
113
|
}
|
102
114
|
|
103
115
|
getSourceString(runtime) {
|
104
116
|
const request =
|
105
|
-
typeof this.request === "object"
|
117
|
+
typeof this.request === "object" && !Array.isArray(this.request)
|
106
118
|
? this.request[this.externalType]
|
107
119
|
: this.request;
|
108
120
|
switch (this.externalType) {
|
@@ -8,10 +8,18 @@ const createHash = require("./util/createHash");
|
|
8
8
|
const validateOptions = require("schema-utils");
|
9
9
|
const schema = require("../schemas/plugins/HashedModuleIdsPlugin.json");
|
10
10
|
|
11
|
+
/** @typedef {import("../declarations/plugins/HashedModuleIdsPlugin").HashedModuleIdsPluginOptions} HashedModuleIdsPluginOptions */
|
12
|
+
|
11
13
|
class HashedModuleIdsPlugin {
|
14
|
+
/**
|
15
|
+
* @param {HashedModuleIdsPluginOptions=} options options object
|
16
|
+
*/
|
12
17
|
constructor(options) {
|
13
|
-
|
18
|
+
if (!options) options = {};
|
19
|
+
|
20
|
+
validateOptions(schema, options, "Hashed Module Ids Plugin");
|
14
21
|
|
22
|
+
/** @type {HashedModuleIdsPluginOptions} */
|
15
23
|
this.options = Object.assign(
|
16
24
|
{
|
17
25
|
context: null,
|
package/lib/HotUpdateChunk.js
CHANGED
package/lib/IgnorePlugin.js
CHANGED
@@ -7,15 +7,12 @@
|
|
7
7
|
const validateOptions = require("schema-utils");
|
8
8
|
const schema = require("../schemas/plugins/IgnorePlugin.json");
|
9
9
|
|
10
|
+
/** @typedef {import("../declarations/plugins/IgnorePlugin").IgnorePluginOptions} IgnorePluginOptions */
|
10
11
|
/** @typedef {import("./Compiler")} Compiler */
|
11
12
|
|
12
13
|
class IgnorePlugin {
|
13
14
|
/**
|
14
|
-
* @param {
|
15
|
-
* @param {RegExp} options.resourceRegExp - A RegExp to test the request against
|
16
|
-
* @param {RegExp} options.contextRegExp - A RegExp to test the context (directory) against
|
17
|
-
* @param {function(string): boolean=} options.checkResource - A filter function for resource
|
18
|
-
* @param {function(string): boolean=} options.checkContext - A filter function for context
|
15
|
+
* @param {IgnorePluginOptions} options IgnorePlugin options
|
19
16
|
*/
|
20
17
|
constructor(options) {
|
21
18
|
// TODO webpack 5 remove this compat-layer
|
@@ -39,13 +36,13 @@ class IgnorePlugin {
|
|
39
36
|
* and the resource given matches the regexp.
|
40
37
|
*/
|
41
38
|
checkResource(resource) {
|
42
|
-
if (this.options.checkResource) {
|
39
|
+
if ("checkResource" in this.options && this.options.checkResource) {
|
43
40
|
return this.options.checkResource(resource);
|
44
41
|
}
|
45
|
-
if (
|
46
|
-
return
|
42
|
+
if ("resourceRegExp" in this.options && this.options.resourceRegExp) {
|
43
|
+
return this.options.resourceRegExp.test(resource);
|
47
44
|
}
|
48
|
-
return
|
45
|
+
return false;
|
49
46
|
}
|
50
47
|
|
51
48
|
/**
|
@@ -54,14 +51,13 @@ class IgnorePlugin {
|
|
54
51
|
* or if context matches the given regexp.
|
55
52
|
*/
|
56
53
|
checkContext(context) {
|
57
|
-
if (this.options.checkContext) {
|
54
|
+
if ("checkContext" in this.options && this.options.checkContext) {
|
58
55
|
return this.options.checkContext(context);
|
59
56
|
}
|
60
|
-
|
61
|
-
|
62
|
-
return true;
|
57
|
+
if ("contextRegExp" in this.options && this.options.contextRegExp) {
|
58
|
+
return this.options.contextRegExp.test(context);
|
63
59
|
}
|
64
|
-
return
|
60
|
+
return true;
|
65
61
|
}
|
66
62
|
|
67
63
|
/**
|
@@ -6,6 +6,7 @@
|
|
6
6
|
|
7
7
|
const SetVarMainTemplatePlugin = require("./SetVarMainTemplatePlugin");
|
8
8
|
|
9
|
+
/** @typedef {import("../declarations/WebpackOptions").LibraryCustomUmdObject} LibraryCustomUmdObject */
|
9
10
|
/** @typedef {import("./Compiler")} Compiler */
|
10
11
|
|
11
12
|
/**
|
@@ -18,12 +19,17 @@ const accessorToObjectAccess = accessor => {
|
|
18
19
|
|
19
20
|
/**
|
20
21
|
* @param {string=} base the path prefix
|
21
|
-
* @param {string|string[]} accessor the accessor
|
22
|
+
* @param {string|string[]|LibraryCustomUmdObject} accessor the accessor
|
23
|
+
* @param {"amd" | "commonjs" | "root"} umdProperty property used when a custom umd object is provided
|
22
24
|
* @param {string=} joinWith the element separator
|
23
25
|
* @returns {string} the path
|
24
26
|
*/
|
25
|
-
const accessorAccess = (base, accessor, joinWith = "; ") => {
|
26
|
-
const
|
27
|
+
const accessorAccess = (base, accessor, umdProperty, joinWith = "; ") => {
|
28
|
+
const normalizedAccessor =
|
29
|
+
typeof accessor === "object" ? accessor[umdProperty] : accessor;
|
30
|
+
const accessors = Array.isArray(normalizedAccessor)
|
31
|
+
? normalizedAccessor
|
32
|
+
: [normalizedAccessor];
|
27
33
|
return accessors
|
28
34
|
.map((_, idx) => {
|
29
35
|
const a = base
|
@@ -40,7 +46,7 @@ const accessorAccess = (base, accessor, joinWith = "; ") => {
|
|
40
46
|
|
41
47
|
class LibraryTemplatePlugin {
|
42
48
|
/**
|
43
|
-
* @param {string} name name of library
|
49
|
+
* @param {string|string[]|LibraryCustomUmdObject} name name of library
|
44
50
|
* @param {string} target type of library
|
45
51
|
* @param {boolean} umdNamedDefine setting this to true will name the UMD module
|
46
52
|
* @param {string|TODO} auxiliaryComment comment in the UMD wrapper
|
@@ -68,14 +74,22 @@ class LibraryTemplatePlugin {
|
|
68
74
|
}
|
69
75
|
switch (this.target) {
|
70
76
|
case "var":
|
77
|
+
if (
|
78
|
+
!this.name ||
|
79
|
+
(typeof this.name === "object" && !Array.isArray(this.name))
|
80
|
+
) {
|
81
|
+
throw new Error(
|
82
|
+
"library name must be set and not an UMD custom object for non-UMD target"
|
83
|
+
);
|
84
|
+
}
|
71
85
|
new SetVarMainTemplatePlugin(
|
72
|
-
`var ${accessorAccess(undefined, this.name)}`,
|
86
|
+
`var ${accessorAccess(undefined, this.name, "root")}`,
|
73
87
|
false
|
74
88
|
).apply(compilation);
|
75
89
|
break;
|
76
90
|
case "assign":
|
77
91
|
new SetVarMainTemplatePlugin(
|
78
|
-
accessorAccess(undefined, this.name),
|
92
|
+
accessorAccess(undefined, this.name, "root"),
|
79
93
|
false
|
80
94
|
).apply(compilation);
|
81
95
|
break;
|
@@ -84,7 +98,7 @@ class LibraryTemplatePlugin {
|
|
84
98
|
case "window":
|
85
99
|
if (this.name) {
|
86
100
|
new SetVarMainTemplatePlugin(
|
87
|
-
accessorAccess(this.target, this.name),
|
101
|
+
accessorAccess(this.target, this.name, "root"),
|
88
102
|
false
|
89
103
|
).apply(compilation);
|
90
104
|
} else {
|
@@ -96,7 +110,8 @@ class LibraryTemplatePlugin {
|
|
96
110
|
new SetVarMainTemplatePlugin(
|
97
111
|
accessorAccess(
|
98
112
|
compilation.runtimeTemplate.outputOptions.globalObject,
|
99
|
-
this.name
|
113
|
+
this.name,
|
114
|
+
"root"
|
100
115
|
),
|
101
116
|
false
|
102
117
|
).apply(compilation);
|
@@ -110,7 +125,7 @@ class LibraryTemplatePlugin {
|
|
110
125
|
case "commonjs":
|
111
126
|
if (this.name) {
|
112
127
|
new SetVarMainTemplatePlugin(
|
113
|
-
accessorAccess("exports", this.name),
|
128
|
+
accessorAccess("exports", this.name, "commonjs"),
|
114
129
|
false
|
115
130
|
).apply(compilation);
|
116
131
|
} else {
|
@@ -125,7 +140,13 @@ class LibraryTemplatePlugin {
|
|
125
140
|
break;
|
126
141
|
case "amd": {
|
127
142
|
const AmdMainTemplatePlugin = require("./AmdMainTemplatePlugin");
|
128
|
-
|
143
|
+
if (this.name) {
|
144
|
+
if (typeof this.name !== "string")
|
145
|
+
throw new Error("library name must be a string for amd target");
|
146
|
+
new AmdMainTemplatePlugin(this.name).apply(compilation);
|
147
|
+
} else {
|
148
|
+
new AmdMainTemplatePlugin().apply(compilation);
|
149
|
+
}
|
129
150
|
break;
|
130
151
|
}
|
131
152
|
case "umd":
|
@@ -140,6 +161,8 @@ class LibraryTemplatePlugin {
|
|
140
161
|
}
|
141
162
|
case "jsonp": {
|
142
163
|
const JsonpExportMainTemplatePlugin = require("./web/JsonpExportMainTemplatePlugin");
|
164
|
+
if (typeof this.name !== "string")
|
165
|
+
throw new Error("library name must be a string for jsonp target");
|
143
166
|
new JsonpExportMainTemplatePlugin(this.name).apply(compilation);
|
144
167
|
break;
|
145
168
|
}
|
@@ -9,7 +9,12 @@ const ModuleFilenameHelpers = require("./ModuleFilenameHelpers");
|
|
9
9
|
const validateOptions = require("schema-utils");
|
10
10
|
const schema = require("../schemas/plugins/LoaderOptionsPlugin.json");
|
11
11
|
|
12
|
+
/** @typedef {import("../declarations/plugins/LoaderOptionsPlugin").LoaderOptionsPluginOptions} LoaderOptionsPluginOptions */
|
13
|
+
|
12
14
|
class LoaderOptionsPlugin {
|
15
|
+
/**
|
16
|
+
* @param {LoaderOptionsPluginOptions} options options object
|
17
|
+
*/
|
13
18
|
constructor(options) {
|
14
19
|
validateOptions(schema, options || {}, "Loader Options Plugin");
|
15
20
|
|