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,160 +1,160 @@
1
- /*
2
- MIT License http://www.opensource.org/licenses/mit-license.php
3
- Author Tobias Koppers @sokra
4
- */
5
- "use strict";
6
-
7
- const identifierUtils = require("./util/identifier");
8
-
9
- class RecordIdsPlugin {
10
- constructor(options) {
11
- this.options = options || {};
12
- }
13
-
14
- apply(compiler) {
15
- const portableIds = this.options.portableIds;
16
- compiler.hooks.compilation.tap("RecordIdsPlugin", compilation => {
17
- compilation.hooks.recordModules.tap(
18
- "RecordIdsPlugin",
19
- (modules, records) => {
20
- if (!records.modules) records.modules = {};
21
- if (!records.modules.byIdentifier) records.modules.byIdentifier = {};
22
- if (!records.modules.usedIds) records.modules.usedIds = {};
23
- for (const module of modules) {
24
- const identifier = portableIds
25
- ? identifierUtils.makePathsRelative(
26
- compiler.context,
27
- module.identifier(),
28
- compilation.cache
29
- )
30
- : module.identifier();
31
- records.modules.byIdentifier[identifier] = module.id;
32
- records.modules.usedIds[module.id] = module.id;
33
- }
34
- }
35
- );
36
- compilation.hooks.reviveModules.tap(
37
- "RecordIdsPlugin",
38
- (modules, records) => {
39
- if (!records.modules) return;
40
- if (records.modules.byIdentifier) {
41
- const usedIds = new Set();
42
- for (const module of modules) {
43
- if (module.id !== null) continue;
44
- const identifier = portableIds
45
- ? identifierUtils.makePathsRelative(
46
- compiler.context,
47
- module.identifier(),
48
- compilation.cache
49
- )
50
- : module.identifier();
51
- const id = records.modules.byIdentifier[identifier];
52
- if (id === undefined) continue;
53
- if (usedIds.has(id)) continue;
54
- usedIds.add(id);
55
- module.id = id;
56
- }
57
- }
58
- if (Array.isArray(records.modules.usedIds))
59
- compilation.usedModuleIds = new Set(records.modules.usedIds);
60
- }
61
- );
62
-
63
- const getModuleIdentifier = module => {
64
- if (portableIds)
65
- return identifierUtils.makePathsRelative(
66
- compiler.context,
67
- module.identifier(),
68
- compilation.cache
69
- );
70
- return module.identifier();
71
- };
72
-
73
- const getChunkSources = chunk => {
74
- const sources = [];
75
- for (const chunkGroup of chunk.groupsIterable) {
76
- const index = chunkGroup.chunks.indexOf(chunk);
77
- for (const origin of chunkGroup.origins) {
78
- if (origin.module) {
79
- if (origin.request)
80
- sources.push(
81
- `${index} ${getModuleIdentifier(origin.module)} ${
82
- origin.request
83
- }`
84
- );
85
- else if (typeof origin.loc === "string")
86
- sources.push(
87
- `${index} ${getModuleIdentifier(origin.module)} ${origin.loc}`
88
- );
89
- else if (
90
- origin.loc &&
91
- typeof origin.loc === "object" &&
92
- origin.loc.start
93
- )
94
- sources.push(
95
- `${index} ${getModuleIdentifier(
96
- origin.module
97
- )} ${JSON.stringify(origin.loc.start)}`
98
- );
99
- }
100
- }
101
- }
102
- return sources;
103
- };
104
-
105
- compilation.hooks.recordChunks.tap(
106
- "RecordIdsPlugin",
107
- (chunks, records) => {
108
- if (!records.chunks) records.chunks = {};
109
- if (!records.chunks.byName) records.chunks.byName = {};
110
- if (!records.chunks.bySource) records.chunks.bySource = {};
111
- const usedIds = new Set();
112
- for (const chunk of chunks) {
113
- const name = chunk.name;
114
- if (name) records.chunks.byName[name] = chunk.id;
115
- const sources = getChunkSources(chunk);
116
- for (const source of sources) {
117
- records.chunks.bySource[source] = chunk.id;
118
- }
119
- usedIds.add(chunk.id);
120
- }
121
- records.chunks.usedIds = Array.from(usedIds);
122
- }
123
- );
124
- compilation.hooks.reviveChunks.tap(
125
- "RecordIdsPlugin",
126
- (chunks, records) => {
127
- if (!records.chunks) return;
128
- const usedIds = new Set();
129
- if (records.chunks.byName) {
130
- for (const chunk of chunks) {
131
- if (chunk.id !== null) continue;
132
- if (!chunk.name) continue;
133
- const id = records.chunks.byName[chunk.name];
134
- if (id === undefined) continue;
135
- if (usedIds.has(id)) continue;
136
- usedIds.add(id);
137
- chunk.id = id;
138
- }
139
- }
140
- if (records.chunks.bySource) {
141
- for (const chunk of chunks) {
142
- const sources = getChunkSources(chunk);
143
- for (const source of sources) {
144
- const id = records.chunks.bySource[source];
145
- if (id === undefined) continue;
146
- if (usedIds[id]) continue;
147
- usedIds[id] = true;
148
- chunk.id = id;
149
- break;
150
- }
151
- }
152
- }
153
- if (Array.isArray(records.chunks.usedIds))
154
- compilation.usedChunkIds = new Set(records.chunks.usedIds);
155
- }
156
- );
157
- });
158
- }
159
- }
160
- module.exports = RecordIdsPlugin;
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Tobias Koppers @sokra
4
+ */
5
+ "use strict";
6
+
7
+ const identifierUtils = require("./util/identifier");
8
+
9
+ class RecordIdsPlugin {
10
+ constructor(options) {
11
+ this.options = options || {};
12
+ }
13
+
14
+ apply(compiler) {
15
+ const portableIds = this.options.portableIds;
16
+ compiler.hooks.compilation.tap("RecordIdsPlugin", compilation => {
17
+ compilation.hooks.recordModules.tap(
18
+ "RecordIdsPlugin",
19
+ (modules, records) => {
20
+ if (!records.modules) records.modules = {};
21
+ if (!records.modules.byIdentifier) records.modules.byIdentifier = {};
22
+ if (!records.modules.usedIds) records.modules.usedIds = {};
23
+ for (const module of modules) {
24
+ const identifier = portableIds
25
+ ? identifierUtils.makePathsRelative(
26
+ compiler.context,
27
+ module.identifier(),
28
+ compilation.cache
29
+ )
30
+ : module.identifier();
31
+ records.modules.byIdentifier[identifier] = module.id;
32
+ records.modules.usedIds[module.id] = module.id;
33
+ }
34
+ }
35
+ );
36
+ compilation.hooks.reviveModules.tap(
37
+ "RecordIdsPlugin",
38
+ (modules, records) => {
39
+ if (!records.modules) return;
40
+ if (records.modules.byIdentifier) {
41
+ const usedIds = new Set();
42
+ for (const module of modules) {
43
+ if (module.id !== null) continue;
44
+ const identifier = portableIds
45
+ ? identifierUtils.makePathsRelative(
46
+ compiler.context,
47
+ module.identifier(),
48
+ compilation.cache
49
+ )
50
+ : module.identifier();
51
+ const id = records.modules.byIdentifier[identifier];
52
+ if (id === undefined) continue;
53
+ if (usedIds.has(id)) continue;
54
+ usedIds.add(id);
55
+ module.id = id;
56
+ }
57
+ }
58
+ if (Array.isArray(records.modules.usedIds))
59
+ compilation.usedModuleIds = new Set(records.modules.usedIds);
60
+ }
61
+ );
62
+
63
+ const getModuleIdentifier = module => {
64
+ if (portableIds)
65
+ return identifierUtils.makePathsRelative(
66
+ compiler.context,
67
+ module.identifier(),
68
+ compilation.cache
69
+ );
70
+ return module.identifier();
71
+ };
72
+
73
+ const getChunkSources = chunk => {
74
+ const sources = [];
75
+ for (const chunkGroup of chunk.groupsIterable) {
76
+ const index = chunkGroup.chunks.indexOf(chunk);
77
+ for (const origin of chunkGroup.origins) {
78
+ if (origin.module) {
79
+ if (origin.request)
80
+ sources.push(
81
+ `${index} ${getModuleIdentifier(origin.module)} ${
82
+ origin.request
83
+ }`
84
+ );
85
+ else if (typeof origin.loc === "string")
86
+ sources.push(
87
+ `${index} ${getModuleIdentifier(origin.module)} ${origin.loc}`
88
+ );
89
+ else if (
90
+ origin.loc &&
91
+ typeof origin.loc === "object" &&
92
+ origin.loc.start
93
+ )
94
+ sources.push(
95
+ `${index} ${getModuleIdentifier(
96
+ origin.module
97
+ )} ${JSON.stringify(origin.loc.start)}`
98
+ );
99
+ }
100
+ }
101
+ }
102
+ return sources;
103
+ };
104
+
105
+ compilation.hooks.recordChunks.tap(
106
+ "RecordIdsPlugin",
107
+ (chunks, records) => {
108
+ if (!records.chunks) records.chunks = {};
109
+ if (!records.chunks.byName) records.chunks.byName = {};
110
+ if (!records.chunks.bySource) records.chunks.bySource = {};
111
+ const usedIds = new Set();
112
+ for (const chunk of chunks) {
113
+ const name = chunk.name;
114
+ if (name) records.chunks.byName[name] = chunk.id;
115
+ const sources = getChunkSources(chunk);
116
+ for (const source of sources) {
117
+ records.chunks.bySource[source] = chunk.id;
118
+ }
119
+ usedIds.add(chunk.id);
120
+ }
121
+ records.chunks.usedIds = Array.from(usedIds);
122
+ }
123
+ );
124
+ compilation.hooks.reviveChunks.tap(
125
+ "RecordIdsPlugin",
126
+ (chunks, records) => {
127
+ if (!records.chunks) return;
128
+ const usedIds = new Set();
129
+ if (records.chunks.byName) {
130
+ for (const chunk of chunks) {
131
+ if (chunk.id !== null) continue;
132
+ if (!chunk.name) continue;
133
+ const id = records.chunks.byName[chunk.name];
134
+ if (id === undefined) continue;
135
+ if (usedIds.has(id)) continue;
136
+ usedIds.add(id);
137
+ chunk.id = id;
138
+ }
139
+ }
140
+ if (records.chunks.bySource) {
141
+ for (const chunk of chunks) {
142
+ const sources = getChunkSources(chunk);
143
+ for (const source of sources) {
144
+ const id = records.chunks.bySource[source];
145
+ if (id === undefined) continue;
146
+ if (usedIds[id]) continue;
147
+ usedIds[id] = true;
148
+ chunk.id = id;
149
+ break;
150
+ }
151
+ }
152
+ }
153
+ if (Array.isArray(records.chunks.usedIds))
154
+ compilation.usedChunkIds = new Set(records.chunks.usedIds);
155
+ }
156
+ );
157
+ });
158
+ }
159
+ }
160
+ module.exports = RecordIdsPlugin;
@@ -1,13 +1,13 @@
1
- "use strict";
2
-
3
- const WebpackError = require("./WebpackError");
4
-
5
- module.exports = class RemovedPluginError extends WebpackError {
6
- constructor(message) {
7
- super();
8
-
9
- this.message = message;
10
-
11
- Error.captureStackTrace(this, this.constructor);
12
- }
13
- };
1
+ "use strict";
2
+
3
+ const WebpackError = require("./WebpackError");
4
+
5
+ module.exports = class RemovedPluginError extends WebpackError {
6
+ constructor(message) {
7
+ super();
8
+
9
+ this.message = message;
10
+
11
+ Error.captureStackTrace(this, this.constructor);
12
+ }
13
+ };
@@ -1,67 +1,64 @@
1
- /*
2
- MIT License http://www.opensource.org/licenses/mit-license.php
3
- Author Tobias Koppers @sokra
4
- */
5
- "use strict";
6
-
7
- const Tapable = require("tapable").Tapable;
8
- const HookMap = require("tapable").HookMap;
9
- const SyncHook = require("tapable").SyncHook;
10
- const SyncWaterfallHook = require("tapable").SyncWaterfallHook;
11
- const Factory = require("enhanced-resolve").ResolverFactory;
12
-
13
- module.exports = class ResolverFactory extends Tapable {
14
- constructor() {
15
- super();
16
- this.hooks = {
17
- resolveOptions: new HookMap(
18
- () => new SyncWaterfallHook(["resolveOptions"])
19
- ),
20
- resolver: new HookMap(() => new SyncHook(["resolver", "resolveOptions"]))
21
- };
22
- this._pluginCompat.tap("ResolverFactory", options => {
23
- let match;
24
- match = /^resolve-options (.+)$/.exec(options.name);
25
- if (match) {
26
- this.hooks.resolveOptions.tap(
27
- match[1],
28
- options.fn.name || "unnamed compat plugin",
29
- options.fn
30
- );
31
- return true;
32
- }
33
- match = /^resolver (.+)$/.exec(options.name);
34
- if (match) {
35
- this.hooks.resolver.tap(
36
- match[1],
37
- options.fn.name || "unnamed compat plugin",
38
- options.fn
39
- );
40
- return true;
41
- }
42
- });
43
- this.cache1 = new WeakMap();
44
- this.cache2 = new Map();
45
- }
46
-
47
- get(type, resolveOptions) {
48
- const cachedResolver = this.cache1.get(resolveOptions);
49
- if (cachedResolver) return cachedResolver();
50
- const ident = `${type}|${JSON.stringify(resolveOptions)}`;
51
- const resolver = this.cache2.get(ident);
52
- if (resolver) return resolver;
53
- const newResolver = this._create(type, resolveOptions);
54
- this.cache2.set(ident, newResolver);
55
- return newResolver;
56
- }
57
-
58
- _create(type, resolveOptions) {
59
- resolveOptions = this.hooks.resolveOptions.for(type).call(resolveOptions);
60
- const resolver = Factory.createResolver(resolveOptions);
61
- if (!resolver) {
62
- throw new Error("No resolver created");
63
- }
64
- this.hooks.resolver.for(type).call(resolver, resolveOptions);
65
- return resolver;
66
- }
67
- };
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Tobias Koppers @sokra
4
+ */
5
+ "use strict";
6
+
7
+ const { Tapable, HookMap, SyncHook, SyncWaterfallHook } = require("tapable");
8
+ const Factory = require("enhanced-resolve").ResolverFactory;
9
+
10
+ module.exports = class ResolverFactory extends Tapable {
11
+ constructor() {
12
+ super();
13
+ this.hooks = {
14
+ resolveOptions: new HookMap(
15
+ () => new SyncWaterfallHook(["resolveOptions"])
16
+ ),
17
+ resolver: new HookMap(() => new SyncHook(["resolver", "resolveOptions"]))
18
+ };
19
+ this._pluginCompat.tap("ResolverFactory", options => {
20
+ let match;
21
+ match = /^resolve-options (.+)$/.exec(options.name);
22
+ if (match) {
23
+ this.hooks.resolveOptions.tap(
24
+ match[1],
25
+ options.fn.name || "unnamed compat plugin",
26
+ options.fn
27
+ );
28
+ return true;
29
+ }
30
+ match = /^resolver (.+)$/.exec(options.name);
31
+ if (match) {
32
+ this.hooks.resolver.tap(
33
+ match[1],
34
+ options.fn.name || "unnamed compat plugin",
35
+ options.fn
36
+ );
37
+ return true;
38
+ }
39
+ });
40
+ this.cache1 = new WeakMap();
41
+ this.cache2 = new Map();
42
+ }
43
+
44
+ get(type, resolveOptions) {
45
+ const cachedResolver = this.cache1.get(resolveOptions);
46
+ if (cachedResolver) return cachedResolver();
47
+ const ident = `${type}|${JSON.stringify(resolveOptions)}`;
48
+ const resolver = this.cache2.get(ident);
49
+ if (resolver) return resolver;
50
+ const newResolver = this._create(type, resolveOptions);
51
+ this.cache2.set(ident, newResolver);
52
+ return newResolver;
53
+ }
54
+
55
+ _create(type, resolveOptions) {
56
+ resolveOptions = this.hooks.resolveOptions.for(type).call(resolveOptions);
57
+ const resolver = Factory.createResolver(resolveOptions);
58
+ if (!resolver) {
59
+ throw new Error("No resolver created");
60
+ }
61
+ this.hooks.resolver.for(type).call(resolver, resolveOptions);
62
+ return resolver;
63
+ }
64
+ };