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.
Files changed (118) hide show
  1. package/README.md +719 -721
  2. package/bin/webpack.js +69 -10
  3. package/lib/APIPlugin.js +84 -84
  4. package/lib/AmdMainTemplatePlugin.js +75 -77
  5. package/lib/AsyncDependencyToInitialChunkError.js +21 -23
  6. package/lib/BannerPlugin.js +101 -101
  7. package/lib/Chunk.js +477 -469
  8. package/lib/ChunkTemplate.js +51 -53
  9. package/lib/Compilation.js +1858 -1851
  10. package/lib/Compiler.js +493 -478
  11. package/lib/ConcurrentCompilationError.js +19 -0
  12. package/lib/ContextModule.js +696 -685
  13. package/lib/ContextModuleFactory.js +245 -243
  14. package/lib/DefinePlugin.js +197 -197
  15. package/lib/DelegatedModule.js +101 -101
  16. package/lib/DependenciesBlockVariable.js +51 -52
  17. package/lib/Dependency.js +53 -52
  18. package/lib/DllModule.js +54 -54
  19. package/lib/DllModuleFactory.js +29 -29
  20. package/lib/EnvironmentPlugin.js +65 -67
  21. package/lib/EvalDevToolModuleTemplatePlugin.js +60 -60
  22. package/lib/EvalSourceMapDevToolModuleTemplatePlugin.js +105 -105
  23. package/lib/ExportPropertyMainTemplatePlugin.js +40 -40
  24. package/lib/ExternalModule.js +159 -159
  25. package/lib/FunctionModuleTemplatePlugin.js +98 -98
  26. package/lib/HotModuleReplacement.runtime.js +631 -631
  27. package/lib/HotModuleReplacementPlugin.js +407 -406
  28. package/lib/HotUpdateChunkTemplate.js +78 -80
  29. package/lib/JavascriptGenerator.js +228 -229
  30. package/lib/JavascriptModulesPlugin.js +184 -158
  31. package/lib/JsonGenerator.js +42 -42
  32. package/lib/MainTemplate.js +406 -402
  33. package/lib/Module.js +343 -340
  34. package/lib/ModuleBuildError.js +42 -42
  35. package/lib/ModuleError.js +28 -28
  36. package/lib/ModuleFilenameHelpers.js +166 -166
  37. package/lib/ModuleTemplate.js +77 -79
  38. package/lib/ModuleWarning.js +30 -30
  39. package/lib/MultiCompiler.js +271 -259
  40. package/lib/MultiModule.js +78 -75
  41. package/lib/MultiModuleFactory.js +23 -23
  42. package/lib/MultiWatching.js +38 -37
  43. package/lib/NoModeWarning.js +23 -21
  44. package/lib/NormalModule.js +478 -470
  45. package/lib/NormalModuleFactory.js +483 -481
  46. package/lib/OptionsDefaulter.js +80 -86
  47. package/lib/Parser.js +2074 -2071
  48. package/lib/ProgressPlugin.js +231 -231
  49. package/lib/RawModule.js +54 -55
  50. package/lib/RecordIdsPlugin.js +160 -160
  51. package/lib/RemovedPluginError.js +13 -13
  52. package/lib/ResolverFactory.js +64 -67
  53. package/lib/RuntimeTemplate.js +267 -297
  54. package/lib/SetVarMainTemplatePlugin.js +57 -57
  55. package/lib/SourceMapDevToolPlugin.js +302 -308
  56. package/lib/Stats.js +1234 -1212
  57. package/lib/Template.js +205 -205
  58. package/lib/TemplatedPathPlugin.js +170 -143
  59. package/lib/UmdMainTemplatePlugin.js +264 -269
  60. package/lib/Watching.js +193 -193
  61. package/lib/WebAssemblyParser.js +50 -54
  62. package/lib/WebpackOptionsApply.js +401 -401
  63. package/lib/WebpackOptionsDefaulter.js +337 -317
  64. package/lib/WebpackOptionsValidationError.js +316 -319
  65. package/lib/debug/ProfilingPlugin.js +409 -405
  66. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +328 -311
  67. package/lib/dependencies/AMDRequireContextDependency.js +20 -20
  68. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +270 -241
  69. package/lib/dependencies/HarmonyAcceptImportDependency.js +23 -23
  70. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +620 -606
  71. package/lib/dependencies/HarmonyExportSpecifierDependency.js +53 -53
  72. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +214 -214
  73. package/lib/dependencies/HarmonyImportSpecifierDependency.js +154 -156
  74. package/lib/dependencies/ImportDependenciesBlock.js +17 -17
  75. package/lib/dependencies/ImportDependency.js +34 -34
  76. package/lib/dependencies/ImportEagerDependency.js +32 -32
  77. package/lib/dependencies/ImportParserPlugin.js +175 -179
  78. package/lib/dependencies/ImportWeakDependency.js +34 -34
  79. package/lib/dependencies/JsonExportsDependency.js +25 -25
  80. package/lib/dependencies/ModuleDependency.js +20 -20
  81. package/lib/dependencies/NullDependency.js +20 -20
  82. package/lib/dependencies/RequireContextDependency.js +22 -22
  83. package/lib/dependencies/RequireIncludeDependency.js +40 -40
  84. package/lib/dependencies/WebpackMissingModule.js +20 -22
  85. package/lib/node/NodeChunkTemplatePlugin.js +31 -31
  86. package/lib/node/NodeHotUpdateChunkTemplatePlugin.js +36 -36
  87. package/lib/node/NodeMainTemplatePlugin.js +320 -273
  88. package/lib/node/ReadFileCompileWasmMainTemplatePlugin.js +113 -115
  89. package/lib/optimize/AggressiveSplittingPlugin.js +281 -281
  90. package/lib/optimize/ConcatenatedModule.js +1364 -1366
  91. package/lib/optimize/RemoveParentModulesPlugin.js +114 -114
  92. package/lib/optimize/SplitChunksPlugin.js +519 -491
  93. package/lib/performance/SizeLimitsPlugin.js +105 -105
  94. package/lib/util/TrackingSet.js +35 -35
  95. package/lib/util/objectToMap.js +10 -10
  96. package/lib/wasm/WasmModuleTemplatePlugin.js +106 -106
  97. package/lib/web/JsonpChunkTemplatePlugin.js +47 -47
  98. package/lib/web/JsonpExportMainTemplatePlugin.js +47 -47
  99. package/lib/web/JsonpHotUpdateChunkTemplatePlugin.js +39 -39
  100. package/lib/web/JsonpMainTemplatePlugin.js +425 -403
  101. package/lib/webpack.js +182 -179
  102. package/lib/webworker/WebWorkerChunkTemplatePlugin.js +35 -35
  103. package/lib/webworker/WebWorkerHotUpdateChunkTemplatePlugin.js +40 -40
  104. package/lib/webworker/WebWorkerMainTemplatePlugin.js +177 -154
  105. package/package.json +9 -8
  106. package/schemas/WebpackOptions.json +1973 -1951
  107. package/schemas/ajv.absolutePath.js +55 -29
  108. package/schemas/plugins/BannerPlugin.json +85 -85
  109. package/schemas/plugins/DllPlugin.json +28 -28
  110. package/schemas/plugins/DllReferencePlugin.json +99 -99
  111. package/schemas/plugins/HashedModuleIdsPlugin.json +24 -24
  112. package/schemas/plugins/LoaderOptionsPlugin.json +26 -26
  113. package/schemas/plugins/SourceMapDevToolPlugin.json +187 -187
  114. package/schemas/plugins/WatchIgnorePlugin.json +16 -16
  115. package/schemas/plugins/debug/ProfilingPlugin.json +12 -12
  116. package/schemas/plugins/optimize/AggressiveSplittingPlugin.json +22 -22
  117. package/schemas/plugins/optimize/LimitChunkCountPlugin.json +15 -15
  118. package/schemas/plugins/optimize/MinChunkSizePlugin.json +13 -13
@@ -1,143 +1,170 @@
1
- /*
2
- MIT License http://www.opensource.org/licenses/mit-license.php
3
- Author Jason Anderson @diurnalist
4
- */
5
- "use strict";
6
-
7
- const REGEXP_HASH = /\[hash(?::(\d+))?\]/gi,
8
- REGEXP_CHUNKHASH = /\[chunkhash(?::(\d+))?\]/gi,
9
- REGEXP_MODULEHASH = /\[modulehash(?::(\d+))?\]/gi,
10
- REGEXP_NAME = /\[name\]/gi,
11
- REGEXP_ID = /\[id\]/gi,
12
- REGEXP_MODULEID = /\[moduleid\]/gi,
13
- REGEXP_FILE = /\[file\]/gi,
14
- REGEXP_QUERY = /\[query\]/gi,
15
- REGEXP_FILEBASE = /\[filebase\]/gi;
16
-
17
- // Using global RegExp for .test is dangerous
18
- // We use a normal RegExp instead of .test
19
- const REGEXP_HASH_FOR_TEST = new RegExp(REGEXP_HASH.source, "i"),
20
- REGEXP_CHUNKHASH_FOR_TEST = new RegExp(REGEXP_CHUNKHASH.source, "i"),
21
- REGEXP_NAME_FOR_TEST = new RegExp(REGEXP_NAME.source, "i");
22
-
23
- const withHashLength = (replacer, handlerFn) => {
24
- const fn = (match, hashLength, ...args) => {
25
- const length = hashLength && parseInt(hashLength, 10);
26
- if (length && handlerFn) {
27
- return handlerFn(length);
28
- }
29
- const hash = replacer(match, hashLength, ...args);
30
- return length ? hash.slice(0, length) : hash;
31
- };
32
- return fn;
33
- };
34
-
35
- const getReplacer = (value, allowEmpty) => {
36
- const fn = (match, ...args) => {
37
- // last argument in replacer is the entire input string
38
- const input = args[args.length - 1];
39
- if (value === null || value === undefined) {
40
- if (!allowEmpty)
41
- throw new Error(
42
- `Path variable ${match} not implemented in this context: ${input}`
43
- );
44
- return "";
45
- } else {
46
- return `${value}`;
47
- }
48
- };
49
- return fn;
50
- };
51
-
52
- const replacePathVariables = (path, data) => {
53
- const chunk = data.chunk;
54
- const chunkId = chunk && chunk.id;
55
- const chunkName = chunk && (chunk.name || chunk.id);
56
- const chunkHash = chunk && (chunk.renderedHash || chunk.hash);
57
- const chunkHashWithLength = chunk && chunk.hashWithLength;
58
- const module = data.module;
59
- const moduleId = module && module.id;
60
- const moduleHash = module && (module.renderedHash || module.hash);
61
- const moduleHashWithLength = module && module.hashWithLength;
62
-
63
- if (typeof path === "function") {
64
- path = path(data);
65
- }
66
-
67
- if (data.noChunkHash && REGEXP_CHUNKHASH_FOR_TEST.test(path)) {
68
- throw new Error(
69
- `Cannot use [chunkhash] for chunk in '${path}' (use [hash] instead)`
70
- );
71
- }
72
-
73
- return (
74
- path
75
- .replace(
76
- REGEXP_HASH,
77
- withHashLength(getReplacer(data.hash), data.hashWithLength)
78
- )
79
- .replace(
80
- REGEXP_CHUNKHASH,
81
- withHashLength(getReplacer(chunkHash), chunkHashWithLength)
82
- )
83
- .replace(
84
- REGEXP_MODULEHASH,
85
- withHashLength(getReplacer(moduleHash), moduleHashWithLength)
86
- )
87
- .replace(REGEXP_ID, getReplacer(chunkId))
88
- .replace(REGEXP_MODULEID, getReplacer(moduleId))
89
- .replace(REGEXP_NAME, getReplacer(chunkName))
90
- .replace(REGEXP_FILE, getReplacer(data.filename))
91
- .replace(REGEXP_FILEBASE, getReplacer(data.basename))
92
- // query is optional, it's OK if it's in a path but there's nothing to replace it with
93
- .replace(REGEXP_QUERY, getReplacer(data.query, true))
94
- );
95
- };
96
-
97
- class TemplatedPathPlugin {
98
- apply(compiler) {
99
- compiler.hooks.compilation.tap("TemplatedPathPlugin", compilation => {
100
- const mainTemplate = compilation.mainTemplate;
101
-
102
- mainTemplate.hooks.assetPath.tap(
103
- "TemplatedPathPlugin",
104
- replacePathVariables
105
- );
106
-
107
- mainTemplate.hooks.globalHash.tap(
108
- "TemplatedPathPlugin",
109
- (chunk, paths) => {
110
- const outputOptions = mainTemplate.outputOptions;
111
- const publicPath = outputOptions.publicPath || "";
112
- const filename = outputOptions.filename || "";
113
- const chunkFilename =
114
- outputOptions.chunkFilename || outputOptions.filename;
115
- if (
116
- REGEXP_HASH_FOR_TEST.test(publicPath) ||
117
- REGEXP_CHUNKHASH_FOR_TEST.test(publicPath) ||
118
- REGEXP_NAME_FOR_TEST.test(publicPath)
119
- )
120
- return true;
121
- if (REGEXP_HASH_FOR_TEST.test(filename)) return true;
122
- if (REGEXP_HASH_FOR_TEST.test(chunkFilename)) return true;
123
- if (REGEXP_HASH_FOR_TEST.test(paths.join("|"))) return true;
124
- }
125
- );
126
-
127
- mainTemplate.hooks.hashForChunk.tap(
128
- "TemplatedPathPlugin",
129
- (hash, chunk) => {
130
- const outputOptions = mainTemplate.outputOptions;
131
- const chunkFilename =
132
- outputOptions.chunkFilename || outputOptions.filename;
133
- if (REGEXP_CHUNKHASH_FOR_TEST.test(chunkFilename))
134
- hash.update(JSON.stringify(chunk.getChunkMaps(true).hash));
135
- if (REGEXP_NAME_FOR_TEST.test(chunkFilename))
136
- hash.update(JSON.stringify(chunk.getChunkMaps(true).name));
137
- }
138
- );
139
- });
140
- }
141
- }
142
-
143
- module.exports = TemplatedPathPlugin;
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Jason Anderson @diurnalist
4
+ */
5
+ "use strict";
6
+
7
+ const REGEXP_HASH = /\[hash(?::(\d+))?\]/gi,
8
+ REGEXP_CHUNKHASH = /\[chunkhash(?::(\d+))?\]/gi,
9
+ REGEXP_MODULEHASH = /\[modulehash(?::(\d+))?\]/gi,
10
+ REGEXP_CONTENTHASH = /\[contenthash(?::(\d+))?\]/gi,
11
+ REGEXP_NAME = /\[name\]/gi,
12
+ REGEXP_ID = /\[id\]/gi,
13
+ REGEXP_MODULEID = /\[moduleid\]/gi,
14
+ REGEXP_FILE = /\[file\]/gi,
15
+ REGEXP_QUERY = /\[query\]/gi,
16
+ REGEXP_FILEBASE = /\[filebase\]/gi;
17
+
18
+ // Using global RegExp for .test is dangerous
19
+ // We use a normal RegExp instead of .test
20
+ const REGEXP_HASH_FOR_TEST = new RegExp(REGEXP_HASH.source, "i"),
21
+ REGEXP_CHUNKHASH_FOR_TEST = new RegExp(REGEXP_CHUNKHASH.source, "i"),
22
+ REGEXP_CONTENTHASH_FOR_TEST = new RegExp(REGEXP_CONTENTHASH.source, "i"),
23
+ REGEXP_NAME_FOR_TEST = new RegExp(REGEXP_NAME.source, "i");
24
+
25
+ const withHashLength = (replacer, handlerFn) => {
26
+ const fn = (match, hashLength, ...args) => {
27
+ const length = hashLength && parseInt(hashLength, 10);
28
+ if (length && handlerFn) {
29
+ return handlerFn(length);
30
+ }
31
+ const hash = replacer(match, hashLength, ...args);
32
+ return length ? hash.slice(0, length) : hash;
33
+ };
34
+ return fn;
35
+ };
36
+
37
+ const getReplacer = (value, allowEmpty) => {
38
+ const fn = (match, ...args) => {
39
+ // last argument in replacer is the entire input string
40
+ const input = args[args.length - 1];
41
+ if (value === null || value === undefined) {
42
+ if (!allowEmpty)
43
+ throw new Error(
44
+ `Path variable ${match} not implemented in this context: ${input}`
45
+ );
46
+ return "";
47
+ } else {
48
+ return `${value}`;
49
+ }
50
+ };
51
+ return fn;
52
+ };
53
+
54
+ const replacePathVariables = (path, data) => {
55
+ const chunk = data.chunk;
56
+ const chunkId = chunk && chunk.id;
57
+ const chunkName = chunk && (chunk.name || chunk.id);
58
+ const chunkHash = chunk && (chunk.renderedHash || chunk.hash);
59
+ const chunkHashWithLength = chunk && chunk.hashWithLength;
60
+ const contentHashType = data.contentHashType;
61
+ const contentHash =
62
+ (chunk && chunk.contentHash && chunk.contentHash[contentHashType]) ||
63
+ data.contentHash;
64
+ const contentHashWithLength =
65
+ (chunk &&
66
+ chunk.contentHashWithLength &&
67
+ chunk.contentHashWithLength[contentHashType]) ||
68
+ data.contentHashWithLength;
69
+ const module = data.module;
70
+ const moduleId = module && module.id;
71
+ const moduleHash = module && (module.renderedHash || module.hash);
72
+ const moduleHashWithLength = module && module.hashWithLength;
73
+
74
+ if (typeof path === "function") {
75
+ path = path(data);
76
+ }
77
+
78
+ if (
79
+ data.noChunkHash &&
80
+ (REGEXP_CHUNKHASH_FOR_TEST.test(path) ||
81
+ REGEXP_CONTENTHASH_FOR_TEST.test(path))
82
+ ) {
83
+ throw new Error(
84
+ `Cannot use [chunkhash] or [contenthash] for chunk in '${path}' (use [hash] instead)`
85
+ );
86
+ }
87
+
88
+ return (
89
+ path
90
+ .replace(
91
+ REGEXP_HASH,
92
+ withHashLength(getReplacer(data.hash), data.hashWithLength)
93
+ )
94
+ .replace(
95
+ REGEXP_CHUNKHASH,
96
+ withHashLength(getReplacer(chunkHash), chunkHashWithLength)
97
+ )
98
+ .replace(
99
+ REGEXP_CONTENTHASH,
100
+ withHashLength(getReplacer(contentHash), contentHashWithLength)
101
+ )
102
+ .replace(
103
+ REGEXP_MODULEHASH,
104
+ withHashLength(getReplacer(moduleHash), moduleHashWithLength)
105
+ )
106
+ .replace(REGEXP_ID, getReplacer(chunkId))
107
+ .replace(REGEXP_MODULEID, getReplacer(moduleId))
108
+ .replace(REGEXP_NAME, getReplacer(chunkName))
109
+ .replace(REGEXP_FILE, getReplacer(data.filename))
110
+ .replace(REGEXP_FILEBASE, getReplacer(data.basename))
111
+ // query is optional, it's OK if it's in a path but there's nothing to replace it with
112
+ .replace(REGEXP_QUERY, getReplacer(data.query, true))
113
+ );
114
+ };
115
+
116
+ class TemplatedPathPlugin {
117
+ apply(compiler) {
118
+ compiler.hooks.compilation.tap("TemplatedPathPlugin", compilation => {
119
+ const mainTemplate = compilation.mainTemplate;
120
+
121
+ mainTemplate.hooks.assetPath.tap(
122
+ "TemplatedPathPlugin",
123
+ replacePathVariables
124
+ );
125
+
126
+ mainTemplate.hooks.globalHash.tap(
127
+ "TemplatedPathPlugin",
128
+ (chunk, paths) => {
129
+ const outputOptions = mainTemplate.outputOptions;
130
+ const publicPath = outputOptions.publicPath || "";
131
+ const filename = outputOptions.filename || "";
132
+ const chunkFilename =
133
+ outputOptions.chunkFilename || outputOptions.filename;
134
+ if (
135
+ REGEXP_HASH_FOR_TEST.test(publicPath) ||
136
+ REGEXP_CHUNKHASH_FOR_TEST.test(publicPath) ||
137
+ REGEXP_CONTENTHASH_FOR_TEST.test(publicPath) ||
138
+ REGEXP_NAME_FOR_TEST.test(publicPath)
139
+ )
140
+ return true;
141
+ if (REGEXP_HASH_FOR_TEST.test(filename)) return true;
142
+ if (REGEXP_HASH_FOR_TEST.test(chunkFilename)) return true;
143
+ if (REGEXP_HASH_FOR_TEST.test(paths.join("|"))) return true;
144
+ }
145
+ );
146
+
147
+ mainTemplate.hooks.hashForChunk.tap(
148
+ "TemplatedPathPlugin",
149
+ (hash, chunk) => {
150
+ const outputOptions = mainTemplate.outputOptions;
151
+ const chunkFilename =
152
+ outputOptions.chunkFilename || outputOptions.filename;
153
+ if (REGEXP_CHUNKHASH_FOR_TEST.test(chunkFilename))
154
+ hash.update(JSON.stringify(chunk.getChunkMaps(true).hash));
155
+ if (REGEXP_CONTENTHASH_FOR_TEST.test(chunkFilename)) {
156
+ hash.update(
157
+ JSON.stringify(
158
+ chunk.getChunkMaps(true).contentHash.javascript || {}
159
+ )
160
+ );
161
+ }
162
+ if (REGEXP_NAME_FOR_TEST.test(chunkFilename))
163
+ hash.update(JSON.stringify(chunk.getChunkMaps(true).name));
164
+ }
165
+ );
166
+ });
167
+ }
168
+ }
169
+
170
+ module.exports = TemplatedPathPlugin;