webpack 4.9.1 → 4.10.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 +755 -755
- package/SECURITY.md +9 -9
- package/buildin/global.js +20 -20
- package/buildin/harmony-module.js +24 -24
- package/buildin/module.js +22 -22
- package/hot/dev-server.js +61 -61
- package/hot/log-apply-result.js +44 -44
- package/hot/log.js +45 -45
- package/hot/only-dev-server.js +105 -105
- package/hot/poll.js +37 -37
- package/hot/signal.js +62 -62
- package/lib/APIPlugin.js +84 -84
- package/lib/AmdMainTemplatePlugin.js +87 -75
- package/lib/AsyncDependenciesBlock.js +66 -66
- package/lib/AsyncDependencyToInitialChunkError.js +31 -21
- package/lib/AutomaticPrefetchPlugin.js +50 -50
- package/lib/BannerPlugin.js +3 -1
- package/lib/BasicEvaluatedExpression.js +211 -208
- package/lib/CachePlugin.js +102 -95
- package/lib/CaseSensitiveModulesWarning.js +71 -53
- package/lib/Chunk.js +750 -722
- package/lib/ChunkGroup.js +13 -5
- package/lib/ChunkRenderError.js +32 -32
- package/lib/CompatibilityPlugin.js +63 -63
- package/lib/Compilation.js +1947 -1905
- package/lib/Compiler.js +508 -496
- package/lib/ConcurrentCompilationError.js +19 -19
- package/lib/ConstPlugin.js +258 -242
- package/lib/ContextExclusionPlugin.js +17 -17
- package/lib/ContextModule.js +749 -710
- package/lib/ContextModuleFactory.js +256 -245
- package/lib/ContextReplacementPlugin.js +133 -126
- package/lib/DefinePlugin.js +206 -197
- package/lib/DelegatedModule.js +101 -101
- package/lib/DelegatedModuleFactoryPlugin.js +89 -89
- package/lib/DelegatedPlugin.js +39 -39
- package/lib/DependenciesBlock.js +89 -87
- package/lib/DependenciesBlockVariable.js +52 -51
- package/lib/Dependency.js +51 -51
- package/lib/DllEntryPlugin.js +51 -51
- package/lib/DllModule.js +54 -54
- package/lib/DllModuleFactory.js +29 -29
- package/lib/DllPlugin.js +44 -42
- package/lib/DllReferencePlugin.js +84 -84
- package/lib/DynamicEntryPlugin.js +73 -71
- package/lib/EntryOptionPlugin.js +33 -33
- package/lib/EnvironmentPlugin.js +65 -65
- package/lib/ErrorHelpers.js +60 -57
- package/lib/EvalDevToolModulePlugin.js +27 -27
- package/lib/EvalDevToolModuleTemplatePlugin.js +61 -61
- package/lib/EvalSourceMapDevToolPlugin.js +41 -40
- package/lib/ExportPropertyMainTemplatePlugin.js +53 -40
- package/lib/ExtendedAPIPlugin.js +84 -84
- package/lib/ExternalModule.js +159 -159
- package/lib/ExternalModuleFactoryPlugin.js +110 -110
- package/lib/ExternalsPlugin.js +23 -23
- package/lib/FlagDependencyExportsPlugin.js +146 -146
- package/lib/FlagDependencyUsagePlugin.js +110 -104
- package/lib/FlagInitialModulesAsUsedPlugin.js +36 -36
- package/lib/FunctionModulePlugin.js +19 -19
- package/lib/FunctionModuleTemplatePlugin.js +100 -98
- package/lib/GraphHelpers.js +64 -64
- package/lib/HarmonyLinkingError.js +18 -18
- package/lib/HashedModuleIdsPlugin.js +53 -53
- package/lib/HotModuleReplacement.runtime.js +7 -3
- package/lib/HotModuleReplacementPlugin.js +413 -406
- package/lib/HotUpdateChunk.js +16 -16
- package/lib/HotUpdateChunkTemplate.js +78 -78
- package/lib/IgnorePlugin.js +71 -71
- package/lib/JavascriptGenerator.js +229 -228
- package/lib/JavascriptModulesPlugin.js +179 -184
- package/lib/JsonGenerator.js +42 -42
- package/lib/JsonModulesPlugin.js +30 -30
- package/lib/JsonParser.js +27 -26
- package/lib/LibManifestPlugin.js +86 -86
- package/lib/LibraryTemplatePlugin.js +153 -119
- package/lib/LoaderOptionsPlugin.js +53 -52
- package/lib/LoaderTargetPlugin.js +24 -24
- package/lib/MainTemplate.js +34 -9
- package/lib/Module.js +381 -377
- package/lib/ModuleBuildError.js +42 -42
- package/lib/ModuleDependencyError.js +35 -25
- package/lib/ModuleDependencyWarning.js +25 -25
- package/lib/ModuleError.js +28 -28
- package/lib/ModuleFilenameHelpers.js +178 -166
- package/lib/ModuleParseError.js +44 -44
- package/lib/ModuleReason.js +40 -40
- package/lib/ModuleTemplate.js +84 -84
- package/lib/ModuleWarning.js +30 -30
- package/lib/MultiCompiler.js +283 -271
- package/lib/MultiEntryPlugin.js +58 -58
- package/lib/MultiModule.js +81 -78
- package/lib/MultiModuleFactory.js +23 -23
- package/lib/MultiStats.js +92 -92
- package/lib/MultiWatching.js +38 -38
- package/lib/NamedChunksPlugin.js +29 -29
- package/lib/NamedModulesPlugin.js +57 -57
- package/lib/NoEmitOnErrorsPlugin.js +20 -20
- package/lib/NoModeWarning.js +23 -23
- package/lib/NodeStuffPlugin.js +179 -178
- package/lib/NormalModule.js +497 -490
- package/lib/NormalModuleFactory.js +501 -483
- package/lib/NormalModuleReplacementPlugin.js +51 -51
- package/lib/OptionsDefaulter.js +84 -80
- package/lib/Parser.js +2164 -2086
- package/lib/ParserHelpers.js +103 -100
- package/lib/PrefetchPlugin.js +37 -37
- package/lib/ProgressPlugin.js +231 -231
- package/lib/ProvidePlugin.js +86 -86
- package/lib/RawModule.js +56 -54
- package/lib/RecordIdsPlugin.js +166 -162
- package/lib/RemovedPluginError.js +13 -13
- package/lib/RequestShortener.js +81 -74
- package/lib/RequireJsStuffPlugin.js +69 -69
- package/lib/ResolverFactory.js +64 -64
- package/lib/RuleSet.js +555 -534
- package/lib/RuntimeTemplate.js +320 -277
- package/lib/SetVarMainTemplatePlugin.js +69 -57
- package/lib/SingleEntryPlugin.js +44 -44
- package/lib/SizeFormatHelpers.js +24 -24
- package/lib/SourceMapDevToolModuleOptionsPlugin.js +49 -49
- package/lib/SourceMapDevToolPlugin.js +301 -300
- package/lib/Stats.js +1408 -1367
- package/lib/Template.js +4 -2
- package/lib/TemplatedPathPlugin.js +173 -170
- package/lib/UmdMainTemplatePlugin.js +304 -264
- package/lib/UseStrictPlugin.js +48 -48
- package/lib/WarnCaseSensitiveModulesPlugin.js +37 -36
- package/lib/WarnNoModeSetPlugin.js +17 -17
- package/lib/WatchIgnorePlugin.js +100 -100
- package/lib/Watching.js +194 -193
- package/lib/WebpackError.js +25 -19
- package/lib/WebpackOptionsApply.js +421 -405
- package/lib/WebpackOptionsDefaulter.js +347 -344
- package/lib/WebpackOptionsValidationError.js +345 -316
- package/lib/compareLocations.js +56 -56
- package/lib/dependencies/AMDDefineDependency.js +137 -137
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +336 -327
- package/lib/dependencies/AMDPlugin.js +250 -250
- package/lib/dependencies/AMDRequireArrayDependency.js +49 -49
- package/lib/dependencies/AMDRequireContextDependency.js +20 -20
- package/lib/dependencies/AMDRequireDependenciesBlock.js +43 -43
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +273 -270
- package/lib/dependencies/AMDRequireDependency.js +135 -135
- package/lib/dependencies/CommonJsPlugin.js +161 -161
- package/lib/dependencies/CommonJsRequireContextDependency.js +23 -23
- package/lib/dependencies/CommonJsRequireDependencyParserPlugin.js +130 -130
- package/lib/dependencies/ConstDependency.js +33 -33
- package/lib/dependencies/ContextDependency.js +68 -68
- package/lib/dependencies/ContextDependencyTemplateAsId.js +42 -42
- package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +38 -38
- package/lib/dependencies/ContextElementDependency.js +21 -21
- package/lib/dependencies/DelegatedExportsDependency.js +33 -33
- package/lib/dependencies/DependencyReference.js +18 -18
- package/lib/dependencies/HarmonyAcceptDependency.js +45 -45
- package/lib/dependencies/HarmonyAcceptImportDependency.js +23 -23
- package/lib/dependencies/HarmonyCompatibilityDependency.js +31 -31
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +92 -90
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +139 -139
- package/lib/dependencies/HarmonyExportExpressionDependency.js +53 -53
- package/lib/dependencies/HarmonyExportHeaderDependency.js +30 -30
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +620 -603
- package/lib/dependencies/HarmonyExportSpecifierDependency.js +54 -54
- package/lib/dependencies/HarmonyImportDependency.js +104 -94
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +217 -214
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +31 -31
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +166 -156
- package/lib/dependencies/HarmonyInitDependency.js +60 -60
- package/lib/dependencies/HarmonyModulesPlugin.js +146 -146
- package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +26 -26
- package/lib/dependencies/ImportContextDependency.js +23 -23
- package/lib/dependencies/ImportDependenciesBlock.js +18 -18
- package/lib/dependencies/ImportDependency.js +34 -34
- package/lib/dependencies/ImportEagerDependency.js +32 -32
- package/lib/dependencies/ImportParserPlugin.js +233 -232
- package/lib/dependencies/ImportPlugin.js +82 -82
- package/lib/dependencies/ImportWeakDependency.js +34 -34
- package/lib/dependencies/JsonExportsDependency.js +26 -26
- package/lib/dependencies/LoaderPlugin.js +98 -93
- package/lib/dependencies/LocalModuleDependency.js +28 -28
- package/lib/dependencies/LocalModulesHelpers.js +52 -45
- package/lib/dependencies/ModuleDependency.js +20 -20
- package/lib/dependencies/ModuleDependencyTemplateAsId.js +17 -17
- package/lib/dependencies/ModuleDependencyTemplateAsRequireId.js +17 -17
- package/lib/dependencies/MultiEntryDependency.js +20 -20
- package/lib/dependencies/NullDependency.js +20 -20
- package/lib/dependencies/RequireContextDependency.js +22 -22
- package/lib/dependencies/RequireContextDependencyParserPlugin.js +56 -56
- package/lib/dependencies/RequireContextPlugin.js +143 -141
- package/lib/dependencies/RequireEnsureDependenciesBlock.js +33 -33
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +116 -112
- package/lib/dependencies/RequireEnsureDependency.js +58 -58
- package/lib/dependencies/RequireEnsurePlugin.js +74 -74
- package/lib/dependencies/RequireHeaderDependency.js +26 -26
- package/lib/dependencies/RequireIncludeDependency.js +39 -39
- package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +23 -23
- package/lib/dependencies/RequireIncludePlugin.js +61 -61
- package/lib/dependencies/RequireResolveContextDependency.js +23 -23
- package/lib/dependencies/RequireResolveDependencyParserPlugin.js +85 -85
- package/lib/dependencies/RequireResolveHeaderDependency.js +26 -26
- package/lib/dependencies/SingleEntryDependency.js +18 -18
- package/lib/dependencies/SystemPlugin.js +125 -125
- package/lib/dependencies/UnsupportedDependency.js +27 -27
- package/lib/dependencies/WebAssemblyImportDependency.js +48 -44
- package/lib/dependencies/WebpackMissingModule.js +20 -20
- package/lib/dependencies/getFunctionExpression.js +52 -52
- package/lib/formatLocation.js +61 -53
- package/lib/node/NodeChunkTemplatePlugin.js +31 -31
- package/lib/node/NodeEnvironmentPlugin.js +28 -28
- package/lib/node/NodeHotUpdateChunkTemplatePlugin.js +36 -36
- package/lib/node/NodeMainTemplate.runtime.js +27 -27
- package/lib/node/NodeMainTemplateAsync.runtime.js +44 -44
- package/lib/node/NodeMainTemplatePlugin.js +323 -320
- package/lib/node/NodeSourcePlugin.js +144 -140
- package/lib/node/NodeTargetPlugin.js +18 -18
- package/lib/node/NodeTemplatePlugin.js +31 -31
- package/lib/node/NodeWatchFileSystem.js +99 -82
- package/lib/node/ReadFileCompileWasmTemplatePlugin.js +52 -52
- package/lib/optimize/AggressiveMergingPlugin.js +87 -87
- package/lib/optimize/AggressiveSplittingPlugin.js +287 -281
- package/lib/optimize/ChunkModuleIdRangePlugin.js +68 -68
- package/lib/optimize/ConcatenatedModule.js +1420 -1413
- package/lib/optimize/EnsureChunkConditionsPlugin.js +70 -70
- package/lib/optimize/FlagIncludedChunksPlugin.js +99 -99
- package/lib/optimize/LimitChunkCountPlugin.js +66 -66
- package/lib/optimize/MergeDuplicateChunksPlugin.js +78 -75
- package/lib/optimize/MinChunkSizePlugin.js +77 -77
- package/lib/optimize/ModuleConcatenationPlugin.js +470 -457
- package/lib/optimize/OccurrenceOrderPlugin.js +133 -126
- package/lib/optimize/RemoveParentModulesPlugin.js +127 -117
- package/lib/optimize/RuntimeChunkPlugin.js +41 -41
- package/lib/optimize/SideEffectsFlagPlugin.js +158 -156
- package/lib/optimize/SplitChunksPlugin.js +709 -696
- package/lib/performance/AssetsOverSizeLimitWarning.js +30 -30
- package/lib/performance/EntrypointsOverSizeLimitWarning.js +31 -31
- package/lib/performance/NoAsyncChunksWarning.js +21 -21
- package/lib/performance/SizeLimitsPlugin.js +105 -105
- package/lib/util/Semaphore.js +41 -41
- package/lib/util/SortableSet.js +5 -2
- package/lib/util/StackedSetMap.js +12 -5
- package/lib/util/TrackingSet.js +35 -35
- package/lib/util/cachedMerge.js +35 -35
- package/lib/util/createHash.js +77 -77
- package/lib/util/identifier.js +76 -76
- package/lib/validateSchema.js +67 -67
- package/lib/wasm/UnsupportedWebAssemblyFeatureError.js +18 -18
- package/lib/wasm/WasmMainTemplatePlugin.js +310 -304
- package/lib/wasm/WebAssemblyGenerator.js +143 -19
- package/lib/wasm/WebAssemblyJavascriptGenerator.js +90 -107
- package/lib/wasm/WebAssemblyModulesPlugin.js +80 -80
- package/lib/wasm/WebAssemblyParser.js +28 -5
- package/lib/wasm/WebAssemblyUtils.js +48 -0
- package/lib/web/FetchCompileWasmTemplatePlugin.js +25 -25
- package/lib/web/JsonpChunkTemplatePlugin.js +47 -47
- package/lib/web/JsonpExportMainTemplatePlugin.js +47 -47
- package/lib/web/JsonpHotUpdateChunkTemplatePlugin.js +39 -39
- package/lib/web/JsonpMainTemplate.runtime.js +65 -64
- package/lib/web/JsonpMainTemplatePlugin.js +576 -574
- package/lib/web/JsonpTemplatePlugin.js +23 -23
- package/lib/webpack.js +183 -182
- package/lib/webpack.web.js +31 -31
- package/lib/webworker/WebWorkerChunkTemplatePlugin.js +35 -35
- package/lib/webworker/WebWorkerHotUpdateChunkTemplatePlugin.js +40 -40
- package/lib/webworker/WebWorkerMainTemplate.runtime.js +65 -64
- package/lib/webworker/WebWorkerMainTemplatePlugin.js +179 -179
- package/lib/webworker/WebWorkerTemplatePlugin.js +25 -25
- package/package.json +9 -8
- package/schemas/WebpackOptions.json +1988 -1988
- package/schemas/ajv.absolutePath.js +55 -55
- package/schemas/plugins/DllPlugin.json +32 -32
- package/schemas/plugins/DllReferencePlugin.json +99 -99
- package/schemas/plugins/HashedModuleIdsPlugin.json +24 -24
- package/schemas/plugins/LoaderOptionsPlugin.json +26 -26
- package/schemas/plugins/SourceMapDevToolPlugin.json +187 -187
- package/schemas/plugins/WatchIgnorePlugin.json +16 -16
- package/schemas/plugins/debug/ProfilingPlugin.json +12 -12
- package/schemas/plugins/optimize/AggressiveSplittingPlugin.json +22 -22
- package/schemas/plugins/optimize/LimitChunkCountPlugin.json +15 -15
- package/schemas/plugins/optimize/MinChunkSizePlugin.json +13 -13
@@ -1,483 +1,501 @@
|
|
1
|
-
/*
|
2
|
-
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
-
Author Tobias Koppers @sokra
|
4
|
-
*/
|
5
|
-
"use strict";
|
6
|
-
|
7
|
-
const asyncLib = require("neo-async");
|
8
|
-
const {
|
9
|
-
Tapable,
|
10
|
-
AsyncSeriesWaterfallHook,
|
11
|
-
SyncWaterfallHook,
|
12
|
-
SyncBailHook,
|
13
|
-
SyncHook,
|
14
|
-
HookMap
|
15
|
-
} = require("tapable");
|
16
|
-
const NormalModule = require("./NormalModule");
|
17
|
-
const RawModule = require("./RawModule");
|
18
|
-
const RuleSet = require("./RuleSet");
|
19
|
-
const cachedMerge = require("./util/cachedMerge");
|
20
|
-
|
21
|
-
const EMPTY_RESOLVE_OPTIONS = {};
|
22
|
-
|
23
|
-
const loaderToIdent = data => {
|
24
|
-
if (!data.options)
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
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
|
-
)
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
this.
|
112
|
-
this.
|
113
|
-
this.
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
}
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
const
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
}
|
249
|
-
|
250
|
-
const
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
this,
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
}
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
if (
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
}
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
return this.
|
477
|
-
type,
|
478
|
-
|
479
|
-
);
|
480
|
-
}
|
481
|
-
|
482
|
-
|
483
|
-
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Tobias Koppers @sokra
|
4
|
+
*/
|
5
|
+
"use strict";
|
6
|
+
|
7
|
+
const asyncLib = require("neo-async");
|
8
|
+
const {
|
9
|
+
Tapable,
|
10
|
+
AsyncSeriesWaterfallHook,
|
11
|
+
SyncWaterfallHook,
|
12
|
+
SyncBailHook,
|
13
|
+
SyncHook,
|
14
|
+
HookMap
|
15
|
+
} = require("tapable");
|
16
|
+
const NormalModule = require("./NormalModule");
|
17
|
+
const RawModule = require("./RawModule");
|
18
|
+
const RuleSet = require("./RuleSet");
|
19
|
+
const cachedMerge = require("./util/cachedMerge");
|
20
|
+
|
21
|
+
const EMPTY_RESOLVE_OPTIONS = {};
|
22
|
+
|
23
|
+
const loaderToIdent = data => {
|
24
|
+
if (!data.options) {
|
25
|
+
return data.loader;
|
26
|
+
}
|
27
|
+
if (typeof data.options === "string") {
|
28
|
+
return data.loader + "?" + data.options;
|
29
|
+
}
|
30
|
+
if (typeof data.options !== "object") {
|
31
|
+
throw new Error("loader options must be string or object");
|
32
|
+
}
|
33
|
+
if (data.ident) {
|
34
|
+
return data.loader + "??" + data.ident;
|
35
|
+
}
|
36
|
+
return data.loader + "?" + JSON.stringify(data.options);
|
37
|
+
};
|
38
|
+
|
39
|
+
const identToLoaderRequest = resultString => {
|
40
|
+
const idx = resultString.indexOf("?");
|
41
|
+
if (idx >= 0) {
|
42
|
+
const loader = resultString.substr(0, idx);
|
43
|
+
const options = resultString.substr(idx + 1);
|
44
|
+
return {
|
45
|
+
loader,
|
46
|
+
options
|
47
|
+
};
|
48
|
+
} else {
|
49
|
+
return {
|
50
|
+
loader: resultString,
|
51
|
+
options: undefined
|
52
|
+
};
|
53
|
+
}
|
54
|
+
};
|
55
|
+
|
56
|
+
const dependencyCache = new WeakMap();
|
57
|
+
|
58
|
+
class NormalModuleFactory extends Tapable {
|
59
|
+
constructor(context, resolverFactory, options) {
|
60
|
+
super();
|
61
|
+
this.hooks = {
|
62
|
+
resolver: new SyncWaterfallHook(["resolver"]),
|
63
|
+
factory: new SyncWaterfallHook(["factory"]),
|
64
|
+
beforeResolve: new AsyncSeriesWaterfallHook(["data"]),
|
65
|
+
afterResolve: new AsyncSeriesWaterfallHook(["data"]),
|
66
|
+
createModule: new SyncBailHook(["data"]),
|
67
|
+
module: new SyncWaterfallHook(["module", "data"]),
|
68
|
+
createParser: new HookMap(() => new SyncBailHook(["parserOptions"])),
|
69
|
+
parser: new HookMap(() => new SyncHook(["parser", "parserOptions"])),
|
70
|
+
createGenerator: new HookMap(
|
71
|
+
() => new SyncBailHook(["generatorOptions"])
|
72
|
+
),
|
73
|
+
generator: new HookMap(
|
74
|
+
() => new SyncHook(["generator", "generatorOptions"])
|
75
|
+
)
|
76
|
+
};
|
77
|
+
this._pluginCompat.tap("NormalModuleFactory", options => {
|
78
|
+
switch (options.name) {
|
79
|
+
case "before-resolve":
|
80
|
+
case "after-resolve":
|
81
|
+
options.async = true;
|
82
|
+
break;
|
83
|
+
case "parser":
|
84
|
+
this.hooks.parser
|
85
|
+
.for("javascript/auto")
|
86
|
+
.tap(options.fn.name || "unnamed compat plugin", options.fn);
|
87
|
+
return true;
|
88
|
+
}
|
89
|
+
let match;
|
90
|
+
match = /^parser (.+)$/.exec(options.name);
|
91
|
+
if (match) {
|
92
|
+
this.hooks.parser
|
93
|
+
.for(match[1])
|
94
|
+
.tap(
|
95
|
+
options.fn.name || "unnamed compat plugin",
|
96
|
+
options.fn.bind(this)
|
97
|
+
);
|
98
|
+
return true;
|
99
|
+
}
|
100
|
+
match = /^create-parser (.+)$/.exec(options.name);
|
101
|
+
if (match) {
|
102
|
+
this.hooks.createParser
|
103
|
+
.for(match[1])
|
104
|
+
.tap(
|
105
|
+
options.fn.name || "unnamed compat plugin",
|
106
|
+
options.fn.bind(this)
|
107
|
+
);
|
108
|
+
return true;
|
109
|
+
}
|
110
|
+
});
|
111
|
+
this.resolverFactory = resolverFactory;
|
112
|
+
this.ruleSet = new RuleSet(options.defaultRules.concat(options.rules));
|
113
|
+
this.cachePredicate =
|
114
|
+
typeof options.unsafeCache === "function"
|
115
|
+
? options.unsafeCache
|
116
|
+
: Boolean.bind(null, options.unsafeCache);
|
117
|
+
this.context = context || "";
|
118
|
+
this.parserCache = Object.create(null);
|
119
|
+
this.generatorCache = Object.create(null);
|
120
|
+
this.hooks.factory.tap("NormalModuleFactory", () => (result, callback) => {
|
121
|
+
let resolver = this.hooks.resolver.call(null);
|
122
|
+
|
123
|
+
// Ignored
|
124
|
+
if (!resolver) return callback();
|
125
|
+
|
126
|
+
resolver(result, (err, data) => {
|
127
|
+
if (err) return callback(err);
|
128
|
+
|
129
|
+
// Ignored
|
130
|
+
if (!data) return callback();
|
131
|
+
|
132
|
+
// direct module
|
133
|
+
if (typeof data.source === "function") return callback(null, data);
|
134
|
+
|
135
|
+
this.hooks.afterResolve.callAsync(data, (err, result) => {
|
136
|
+
if (err) return callback(err);
|
137
|
+
|
138
|
+
// Ignored
|
139
|
+
if (!result) return callback();
|
140
|
+
|
141
|
+
let createdModule = this.hooks.createModule.call(result);
|
142
|
+
if (!createdModule) {
|
143
|
+
if (!result.request) {
|
144
|
+
return callback(new Error("Empty dependency (no request)"));
|
145
|
+
}
|
146
|
+
|
147
|
+
createdModule = new NormalModule(result);
|
148
|
+
}
|
149
|
+
|
150
|
+
createdModule = this.hooks.module.call(createdModule, result);
|
151
|
+
|
152
|
+
return callback(null, createdModule);
|
153
|
+
});
|
154
|
+
});
|
155
|
+
});
|
156
|
+
this.hooks.resolver.tap("NormalModuleFactory", () => (data, callback) => {
|
157
|
+
const contextInfo = data.contextInfo;
|
158
|
+
const context = data.context;
|
159
|
+
const request = data.request;
|
160
|
+
|
161
|
+
const noPreAutoLoaders = request.startsWith("-!");
|
162
|
+
const noAutoLoaders = noPreAutoLoaders || request.startsWith("!");
|
163
|
+
const noPrePostAutoLoaders = request.startsWith("!!");
|
164
|
+
let elements = request
|
165
|
+
.replace(/^-?!+/, "")
|
166
|
+
.replace(/!!+/g, "!")
|
167
|
+
.split("!");
|
168
|
+
let resource = elements.pop();
|
169
|
+
elements = elements.map(identToLoaderRequest);
|
170
|
+
|
171
|
+
const loaderResolver = this.getResolver("loader");
|
172
|
+
const normalResolver = this.getResolver("normal", data.resolveOptions);
|
173
|
+
|
174
|
+
asyncLib.parallel(
|
175
|
+
[
|
176
|
+
callback =>
|
177
|
+
this.resolveRequestArray(
|
178
|
+
contextInfo,
|
179
|
+
context,
|
180
|
+
elements,
|
181
|
+
loaderResolver,
|
182
|
+
callback
|
183
|
+
),
|
184
|
+
callback => {
|
185
|
+
if (resource === "" || resource[0] === "?") {
|
186
|
+
return callback(null, {
|
187
|
+
resource
|
188
|
+
});
|
189
|
+
}
|
190
|
+
|
191
|
+
normalResolver.resolve(
|
192
|
+
contextInfo,
|
193
|
+
context,
|
194
|
+
resource,
|
195
|
+
{},
|
196
|
+
(err, resource, resourceResolveData) => {
|
197
|
+
if (err) return callback(err);
|
198
|
+
callback(null, {
|
199
|
+
resourceResolveData,
|
200
|
+
resource
|
201
|
+
});
|
202
|
+
}
|
203
|
+
);
|
204
|
+
}
|
205
|
+
],
|
206
|
+
(err, results) => {
|
207
|
+
if (err) return callback(err);
|
208
|
+
let loaders = results[0];
|
209
|
+
const resourceResolveData = results[1].resourceResolveData;
|
210
|
+
resource = results[1].resource;
|
211
|
+
|
212
|
+
// translate option idents
|
213
|
+
try {
|
214
|
+
for (const item of loaders) {
|
215
|
+
if (typeof item.options === "string" && item.options[0] === "?") {
|
216
|
+
const ident = item.options.substr(1);
|
217
|
+
item.options = this.ruleSet.findOptionsByIdent(ident);
|
218
|
+
item.ident = ident;
|
219
|
+
}
|
220
|
+
}
|
221
|
+
} catch (e) {
|
222
|
+
return callback(e);
|
223
|
+
}
|
224
|
+
|
225
|
+
if (resource === false) {
|
226
|
+
// ignored
|
227
|
+
return callback(
|
228
|
+
null,
|
229
|
+
new RawModule(
|
230
|
+
"/* (ignored) */",
|
231
|
+
`ignored ${context} ${request}`,
|
232
|
+
`${request} (ignored)`
|
233
|
+
)
|
234
|
+
);
|
235
|
+
}
|
236
|
+
|
237
|
+
const userRequest = loaders
|
238
|
+
.map(loaderToIdent)
|
239
|
+
.concat([resource])
|
240
|
+
.join("!");
|
241
|
+
|
242
|
+
let resourcePath = resource;
|
243
|
+
let resourceQuery = "";
|
244
|
+
const queryIndex = resourcePath.indexOf("?");
|
245
|
+
if (queryIndex >= 0) {
|
246
|
+
resourceQuery = resourcePath.substr(queryIndex);
|
247
|
+
resourcePath = resourcePath.substr(0, queryIndex);
|
248
|
+
}
|
249
|
+
|
250
|
+
const result = this.ruleSet.exec({
|
251
|
+
resource: resourcePath,
|
252
|
+
resourceQuery,
|
253
|
+
issuer: contextInfo.issuer,
|
254
|
+
compiler: contextInfo.compiler
|
255
|
+
});
|
256
|
+
const settings = {};
|
257
|
+
const useLoadersPost = [];
|
258
|
+
const useLoaders = [];
|
259
|
+
const useLoadersPre = [];
|
260
|
+
for (const r of result) {
|
261
|
+
if (r.type === "use") {
|
262
|
+
if (r.enforce === "post" && !noPrePostAutoLoaders) {
|
263
|
+
useLoadersPost.push(r.value);
|
264
|
+
} else if (
|
265
|
+
r.enforce === "pre" &&
|
266
|
+
!noPreAutoLoaders &&
|
267
|
+
!noPrePostAutoLoaders
|
268
|
+
) {
|
269
|
+
useLoadersPre.push(r.value);
|
270
|
+
} else if (
|
271
|
+
!r.enforce &&
|
272
|
+
!noAutoLoaders &&
|
273
|
+
!noPrePostAutoLoaders
|
274
|
+
) {
|
275
|
+
useLoaders.push(r.value);
|
276
|
+
}
|
277
|
+
} else if (
|
278
|
+
typeof r.value === "object" &&
|
279
|
+
r.value !== null &&
|
280
|
+
typeof settings[r.type] === "object" &&
|
281
|
+
settings[r.type] !== null
|
282
|
+
) {
|
283
|
+
settings[r.type] = cachedMerge(settings[r.type], r.value);
|
284
|
+
} else {
|
285
|
+
settings[r.type] = r.value;
|
286
|
+
}
|
287
|
+
}
|
288
|
+
asyncLib.parallel(
|
289
|
+
[
|
290
|
+
this.resolveRequestArray.bind(
|
291
|
+
this,
|
292
|
+
contextInfo,
|
293
|
+
this.context,
|
294
|
+
useLoadersPost,
|
295
|
+
loaderResolver
|
296
|
+
),
|
297
|
+
this.resolveRequestArray.bind(
|
298
|
+
this,
|
299
|
+
contextInfo,
|
300
|
+
this.context,
|
301
|
+
useLoaders,
|
302
|
+
loaderResolver
|
303
|
+
),
|
304
|
+
this.resolveRequestArray.bind(
|
305
|
+
this,
|
306
|
+
contextInfo,
|
307
|
+
this.context,
|
308
|
+
useLoadersPre,
|
309
|
+
loaderResolver
|
310
|
+
)
|
311
|
+
],
|
312
|
+
(err, results) => {
|
313
|
+
if (err) return callback(err);
|
314
|
+
loaders = results[0].concat(loaders, results[1], results[2]);
|
315
|
+
process.nextTick(() => {
|
316
|
+
const type = settings.type;
|
317
|
+
const resolveOptions = settings.resolve;
|
318
|
+
callback(null, {
|
319
|
+
context: context,
|
320
|
+
request: loaders
|
321
|
+
.map(loaderToIdent)
|
322
|
+
.concat([resource])
|
323
|
+
.join("!"),
|
324
|
+
dependencies: data.dependencies,
|
325
|
+
userRequest,
|
326
|
+
rawRequest: request,
|
327
|
+
loaders,
|
328
|
+
resource,
|
329
|
+
resourceResolveData,
|
330
|
+
settings,
|
331
|
+
type,
|
332
|
+
parser: this.getParser(type, settings.parser),
|
333
|
+
generator: this.getGenerator(type, settings.generator),
|
334
|
+
resolveOptions
|
335
|
+
});
|
336
|
+
});
|
337
|
+
}
|
338
|
+
);
|
339
|
+
}
|
340
|
+
);
|
341
|
+
});
|
342
|
+
}
|
343
|
+
|
344
|
+
create(data, callback) {
|
345
|
+
const dependencies = data.dependencies;
|
346
|
+
const cacheEntry = dependencyCache.get(dependencies[0]);
|
347
|
+
if (cacheEntry) return callback(null, cacheEntry);
|
348
|
+
const context = data.context || this.context;
|
349
|
+
const resolveOptions = data.resolveOptions || EMPTY_RESOLVE_OPTIONS;
|
350
|
+
const request = dependencies[0].request;
|
351
|
+
const contextInfo = data.contextInfo || {};
|
352
|
+
this.hooks.beforeResolve.callAsync(
|
353
|
+
{
|
354
|
+
contextInfo,
|
355
|
+
resolveOptions,
|
356
|
+
context,
|
357
|
+
request,
|
358
|
+
dependencies
|
359
|
+
},
|
360
|
+
(err, result) => {
|
361
|
+
if (err) return callback(err);
|
362
|
+
|
363
|
+
// Ignored
|
364
|
+
if (!result) return callback();
|
365
|
+
|
366
|
+
const factory = this.hooks.factory.call(null);
|
367
|
+
|
368
|
+
// Ignored
|
369
|
+
if (!factory) return callback();
|
370
|
+
|
371
|
+
factory(result, (err, module) => {
|
372
|
+
if (err) return callback(err);
|
373
|
+
|
374
|
+
if (module && this.cachePredicate(module)) {
|
375
|
+
for (const d of dependencies) {
|
376
|
+
dependencyCache.set(d, module);
|
377
|
+
}
|
378
|
+
}
|
379
|
+
|
380
|
+
callback(null, module);
|
381
|
+
});
|
382
|
+
}
|
383
|
+
);
|
384
|
+
}
|
385
|
+
|
386
|
+
resolveRequestArray(contextInfo, context, array, resolver, callback) {
|
387
|
+
if (array.length === 0) return callback(null, []);
|
388
|
+
asyncLib.map(
|
389
|
+
array,
|
390
|
+
(item, callback) => {
|
391
|
+
resolver.resolve(
|
392
|
+
contextInfo,
|
393
|
+
context,
|
394
|
+
item.loader,
|
395
|
+
{},
|
396
|
+
(err, result) => {
|
397
|
+
if (
|
398
|
+
err &&
|
399
|
+
/^[^/]*$/.test(item.loader) &&
|
400
|
+
!/-loader$/.test(item.loader)
|
401
|
+
) {
|
402
|
+
return resolver.resolve(
|
403
|
+
contextInfo,
|
404
|
+
context,
|
405
|
+
item.loader + "-loader",
|
406
|
+
{},
|
407
|
+
err2 => {
|
408
|
+
if (!err2) {
|
409
|
+
err.message =
|
410
|
+
err.message +
|
411
|
+
"\n" +
|
412
|
+
"BREAKING CHANGE: It's no longer allowed to omit the '-loader' suffix when using loaders.\n" +
|
413
|
+
` You need to specify '${
|
414
|
+
item.loader
|
415
|
+
}-loader' instead of '${item.loader}',\n` +
|
416
|
+
" see https://webpack.js.org/migrate/3/#automatic-loader-module-name-extension-removed";
|
417
|
+
}
|
418
|
+
callback(err);
|
419
|
+
}
|
420
|
+
);
|
421
|
+
}
|
422
|
+
if (err) return callback(err);
|
423
|
+
|
424
|
+
const optionsOnly = item.options
|
425
|
+
? {
|
426
|
+
options: item.options
|
427
|
+
}
|
428
|
+
: undefined;
|
429
|
+
return callback(
|
430
|
+
null,
|
431
|
+
Object.assign({}, item, identToLoaderRequest(result), optionsOnly)
|
432
|
+
);
|
433
|
+
}
|
434
|
+
);
|
435
|
+
},
|
436
|
+
callback
|
437
|
+
);
|
438
|
+
}
|
439
|
+
|
440
|
+
getParser(type, parserOptions) {
|
441
|
+
let ident = type;
|
442
|
+
if (parserOptions) {
|
443
|
+
if (parserOptions.ident) {
|
444
|
+
ident = `${type}|${parserOptions.ident}`;
|
445
|
+
} else {
|
446
|
+
ident = JSON.stringify([type, parserOptions]);
|
447
|
+
}
|
448
|
+
}
|
449
|
+
if (ident in this.parserCache) {
|
450
|
+
return this.parserCache[ident];
|
451
|
+
}
|
452
|
+
return (this.parserCache[ident] = this.createParser(type, parserOptions));
|
453
|
+
}
|
454
|
+
|
455
|
+
createParser(type, parserOptions = {}) {
|
456
|
+
const parser = this.hooks.createParser.for(type).call(parserOptions);
|
457
|
+
if (!parser) {
|
458
|
+
throw new Error(`No parser registered for ${type}`);
|
459
|
+
}
|
460
|
+
this.hooks.parser.for(type).call(parser, parserOptions);
|
461
|
+
return parser;
|
462
|
+
}
|
463
|
+
|
464
|
+
getGenerator(type, generatorOptions) {
|
465
|
+
let ident = type;
|
466
|
+
if (generatorOptions) {
|
467
|
+
if (generatorOptions.ident) {
|
468
|
+
ident = `${type}|${generatorOptions.ident}`;
|
469
|
+
} else {
|
470
|
+
ident = JSON.stringify([type, generatorOptions]);
|
471
|
+
}
|
472
|
+
}
|
473
|
+
if (ident in this.generatorCache) {
|
474
|
+
return this.generatorCache[ident];
|
475
|
+
}
|
476
|
+
return (this.generatorCache[ident] = this.createGenerator(
|
477
|
+
type,
|
478
|
+
generatorOptions
|
479
|
+
));
|
480
|
+
}
|
481
|
+
|
482
|
+
createGenerator(type, generatorOptions = {}) {
|
483
|
+
const generator = this.hooks.createGenerator
|
484
|
+
.for(type)
|
485
|
+
.call(generatorOptions);
|
486
|
+
if (!generator) {
|
487
|
+
throw new Error(`No generator registered for ${type}`);
|
488
|
+
}
|
489
|
+
this.hooks.generator.for(type).call(generator, generatorOptions);
|
490
|
+
return generator;
|
491
|
+
}
|
492
|
+
|
493
|
+
getResolver(type, resolveOptions) {
|
494
|
+
return this.resolverFactory.get(
|
495
|
+
type,
|
496
|
+
resolveOptions || EMPTY_RESOLVE_OPTIONS
|
497
|
+
);
|
498
|
+
}
|
499
|
+
}
|
500
|
+
|
501
|
+
module.exports = NormalModuleFactory;
|