webpack 3.3.0 → 3.5.1

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 (40) hide show
  1. package/README.md +34 -11
  2. package/bin/config-optimist.js +1 -0
  3. package/bin/config-yargs.js +12 -4
  4. package/bin/convert-argv.js +28 -8
  5. package/bin/webpack.js +198 -182
  6. package/lib/ContextModule.js +87 -13
  7. package/lib/DelegatedModule.js +10 -4
  8. package/lib/DelegatedModuleFactoryPlugin.js +5 -4
  9. package/lib/DelegatedPlugin.js +3 -0
  10. package/lib/DllReferencePlugin.js +3 -0
  11. package/lib/ExternalModule.js +6 -1
  12. package/lib/ExternalModuleFactoryPlugin.js +1 -1
  13. package/lib/HotModuleReplacement.runtime.js +13 -5
  14. package/lib/MultiCompiler.js +2 -2
  15. package/lib/NormalModule.js +32 -9
  16. package/lib/NormalModuleFactory.js +133 -145
  17. package/lib/Parser.js +52 -58
  18. package/lib/RecordIdsPlugin.js +3 -3
  19. package/lib/SourceMapDevToolPlugin.js +57 -41
  20. package/lib/Stats.js +58 -24
  21. package/lib/Template.js +1 -1
  22. package/lib/dependencies/DelegatedExportsDependency.js +33 -0
  23. package/lib/dependencies/HarmonyCompatibilityDependency.js +1 -1
  24. package/lib/dependencies/ImportParserPlugin.js +11 -4
  25. package/lib/dependencies/ImportPlugin.js +8 -0
  26. package/lib/dependencies/ImportWeakContextDependency.js +22 -0
  27. package/lib/dependencies/ImportWeakDependency.js +47 -0
  28. package/lib/dependencies/RequireContextDependency.js +5 -1
  29. package/lib/dependencies/RequireContextDependencyParserPlugin.js +9 -1
  30. package/lib/dependencies/RequireResolveDependencyParserPlugin.js +1 -1
  31. package/lib/optimize/AggressiveMergingPlugin.js +27 -33
  32. package/lib/optimize/AggressiveSplittingPlugin.js +46 -33
  33. package/lib/optimize/ChunkModuleIdRangePlugin.js +1 -3
  34. package/lib/optimize/CommonsChunkPlugin.js +11 -4
  35. package/lib/optimize/ConcatenatedModule.js +403 -229
  36. package/lib/optimize/ModuleConcatenationPlugin.js +30 -35
  37. package/lib/util/identifier.js +23 -1
  38. package/lib/webpack.js +52 -55
  39. package/package.json +10 -10
  40. package/schemas/webpackOptionsSchema.json +27 -12
package/bin/webpack.js CHANGED
@@ -146,228 +146,244 @@ yargs.options({
146
146
  }
147
147
  });
148
148
 
149
- var argv = yargs.argv;
150
-
151
- if(argv.verbose) {
152
- argv["display"] = "verbose";
153
- }
154
-
155
- var options = require("./convert-argv")(yargs, argv);
156
-
157
- function ifArg(name, fn, init) {
158
- if(Array.isArray(argv[name])) {
159
- if(init) init();
160
- argv[name].forEach(fn);
161
- } else if(typeof argv[name] !== "undefined") {
162
- if(init) init();
163
- fn(argv[name], -1);
164
- }
165
- }
166
-
167
- function processOptions(options) {
168
- // process Promise
169
- if(typeof options.then === "function") {
170
- options.then(processOptions).catch(function(err) {
171
- console.error(err.stack || err);
172
- process.exit(1); // eslint-disable-line
173
- });
149
+ // yargs will terminate the process early when the user uses help or version.
150
+ // This causes large help outputs to be cut short (https://github.com/nodejs/node/wiki/API-changes-between-v0.10-and-v4#process).
151
+ // To prevent this we use the yargs.parse API and exit the process normally
152
+ yargs.parse(process.argv.slice(2), (err, argv, output) => {
153
+
154
+ // arguments validation failed
155
+ if(err && output) {
156
+ console.error(output);
157
+ process.exitCode = 1;
174
158
  return;
175
159
  }
176
160
 
177
- var firstOptions = [].concat(options)[0];
178
- var statsPresetToOptions = require("../lib/Stats.js").presetToOptions;
161
+ // help or version info
162
+ if(output) {
163
+ console.log(output);
164
+ return;
165
+ }
179
166
 
180
- var outputOptions = options.stats;
181
- if(typeof outputOptions === "boolean" || typeof outputOptions === "string") {
182
- outputOptions = statsPresetToOptions(outputOptions);
183
- } else if(!outputOptions) {
184
- outputOptions = {};
167
+ if(argv.verbose) {
168
+ argv["display"] = "verbose";
185
169
  }
186
170
 
187
- ifArg("display", function(preset) {
188
- outputOptions = statsPresetToOptions(preset);
189
- });
171
+ var options = require("./convert-argv")(yargs, argv);
190
172
 
191
- outputOptions = Object.create(outputOptions);
192
- if(Array.isArray(options) && !outputOptions.children) {
193
- outputOptions.children = options.map(o => o.stats);
173
+ function ifArg(name, fn, init) {
174
+ if(Array.isArray(argv[name])) {
175
+ if(init) init();
176
+ argv[name].forEach(fn);
177
+ } else if(typeof argv[name] !== "undefined") {
178
+ if(init) init();
179
+ fn(argv[name], -1);
180
+ }
194
181
  }
195
- if(typeof outputOptions.context === "undefined")
196
- outputOptions.context = firstOptions.context;
197
182
 
198
- ifArg("json", function(bool) {
199
- if(bool)
200
- outputOptions.json = bool;
201
- });
183
+ function processOptions(options) {
184
+ // process Promise
185
+ if(typeof options.then === "function") {
186
+ options.then(processOptions).catch(function(err) {
187
+ console.error(err.stack || err);
188
+ process.exit(1); // eslint-disable-line
189
+ });
190
+ return;
191
+ }
202
192
 
203
- if(typeof outputOptions.colors === "undefined")
204
- outputOptions.colors = require("supports-color");
193
+ var firstOptions = [].concat(options)[0];
194
+ var statsPresetToOptions = require("../lib/Stats.js").presetToOptions;
205
195
 
206
- ifArg("sort-modules-by", function(value) {
207
- outputOptions.modulesSort = value;
208
- });
196
+ var outputOptions = options.stats;
197
+ if(typeof outputOptions === "boolean" || typeof outputOptions === "string") {
198
+ outputOptions = statsPresetToOptions(outputOptions);
199
+ } else if(!outputOptions) {
200
+ outputOptions = {};
201
+ }
209
202
 
210
- ifArg("sort-chunks-by", function(value) {
211
- outputOptions.chunksSort = value;
212
- });
203
+ ifArg("display", function(preset) {
204
+ outputOptions = statsPresetToOptions(preset);
205
+ });
213
206
 
214
- ifArg("sort-assets-by", function(value) {
215
- outputOptions.assetsSort = value;
216
- });
207
+ outputOptions = Object.create(outputOptions);
208
+ if(Array.isArray(options) && !outputOptions.children) {
209
+ outputOptions.children = options.map(o => o.stats);
210
+ }
211
+ if(typeof outputOptions.context === "undefined")
212
+ outputOptions.context = firstOptions.context;
217
213
 
218
- ifArg("display-exclude", function(value) {
219
- outputOptions.exclude = value;
220
- });
214
+ ifArg("json", function(bool) {
215
+ if(bool)
216
+ outputOptions.json = bool;
217
+ });
221
218
 
222
- if(!outputOptions.json) {
223
- if(typeof outputOptions.cached === "undefined")
224
- outputOptions.cached = false;
225
- if(typeof outputOptions.cachedAssets === "undefined")
226
- outputOptions.cachedAssets = false;
219
+ if(typeof outputOptions.colors === "undefined")
220
+ outputOptions.colors = require("supports-color");
227
221
 
228
- ifArg("display-chunks", function(bool) {
229
- if(bool) {
230
- outputOptions.modules = false;
231
- outputOptions.chunks = true;
232
- outputOptions.chunkModules = true;
233
- }
222
+ ifArg("sort-modules-by", function(value) {
223
+ outputOptions.modulesSort = value;
234
224
  });
235
225
 
236
- ifArg("display-entrypoints", function(bool) {
237
- if(bool)
238
- outputOptions.entrypoints = true;
226
+ ifArg("sort-chunks-by", function(value) {
227
+ outputOptions.chunksSort = value;
239
228
  });
240
229
 
241
- ifArg("display-reasons", function(bool) {
242
- if(bool)
243
- outputOptions.reasons = true;
230
+ ifArg("sort-assets-by", function(value) {
231
+ outputOptions.assetsSort = value;
244
232
  });
245
233
 
246
- ifArg("display-depth", function(bool) {
247
- if(bool)
248
- outputOptions.depth = true;
234
+ ifArg("display-exclude", function(value) {
235
+ outputOptions.exclude = value;
249
236
  });
250
237
 
251
- ifArg("display-used-exports", function(bool) {
252
- if(bool)
253
- outputOptions.usedExports = true;
254
- });
238
+ if(!outputOptions.json) {
239
+ if(typeof outputOptions.cached === "undefined")
240
+ outputOptions.cached = false;
241
+ if(typeof outputOptions.cachedAssets === "undefined")
242
+ outputOptions.cachedAssets = false;
243
+
244
+ ifArg("display-chunks", function(bool) {
245
+ if(bool) {
246
+ outputOptions.modules = false;
247
+ outputOptions.chunks = true;
248
+ outputOptions.chunkModules = true;
249
+ }
250
+ });
255
251
 
256
- ifArg("display-provided-exports", function(bool) {
257
- if(bool)
258
- outputOptions.providedExports = true;
259
- });
252
+ ifArg("display-entrypoints", function(bool) {
253
+ if(bool)
254
+ outputOptions.entrypoints = true;
255
+ });
260
256
 
261
- ifArg("display-optimization-bailout", function(bool) {
262
- if(bool)
263
- outputOptions.optimizationBailout = bool;
264
- });
257
+ ifArg("display-reasons", function(bool) {
258
+ if(bool)
259
+ outputOptions.reasons = true;
260
+ });
265
261
 
266
- ifArg("display-error-details", function(bool) {
267
- if(bool)
268
- outputOptions.errorDetails = true;
269
- });
262
+ ifArg("display-depth", function(bool) {
263
+ if(bool)
264
+ outputOptions.depth = true;
265
+ });
270
266
 
271
- ifArg("display-origins", function(bool) {
272
- if(bool)
273
- outputOptions.chunkOrigins = true;
274
- });
267
+ ifArg("display-used-exports", function(bool) {
268
+ if(bool)
269
+ outputOptions.usedExports = true;
270
+ });
275
271
 
276
- ifArg("display-max-modules", function(value) {
277
- outputOptions.maxModules = +value;
278
- });
272
+ ifArg("display-provided-exports", function(bool) {
273
+ if(bool)
274
+ outputOptions.providedExports = true;
275
+ });
279
276
 
280
- ifArg("display-cached", function(bool) {
281
- if(bool)
282
- outputOptions.cached = true;
283
- });
277
+ ifArg("display-optimization-bailout", function(bool) {
278
+ if(bool)
279
+ outputOptions.optimizationBailout = bool;
280
+ });
284
281
 
285
- ifArg("display-cached-assets", function(bool) {
286
- if(bool)
287
- outputOptions.cachedAssets = true;
288
- });
282
+ ifArg("display-error-details", function(bool) {
283
+ if(bool)
284
+ outputOptions.errorDetails = true;
285
+ });
289
286
 
290
- if(!outputOptions.exclude)
291
- outputOptions.exclude = ["node_modules", "bower_components", "components"];
287
+ ifArg("display-origins", function(bool) {
288
+ if(bool)
289
+ outputOptions.chunkOrigins = true;
290
+ });
292
291
 
293
- if(argv["display-modules"]) {
294
- outputOptions.maxModules = Infinity;
295
- outputOptions.exclude = undefined;
296
- outputOptions.modules = true;
297
- }
298
- }
292
+ ifArg("display-max-modules", function(value) {
293
+ outputOptions.maxModules = +value;
294
+ });
299
295
 
300
- ifArg("hide-modules", function(bool) {
301
- if(bool) {
302
- outputOptions.modules = false;
303
- outputOptions.chunkModules = false;
304
- }
305
- });
306
-
307
- var webpack = require("../lib/webpack.js");
308
-
309
- Error.stackTraceLimit = 30;
310
- var lastHash = null;
311
- var compiler;
312
- try {
313
- compiler = webpack(options);
314
- } catch(e) {
315
- var WebpackOptionsValidationError = require("../lib/WebpackOptionsValidationError");
316
- if(e instanceof WebpackOptionsValidationError) {
317
- if(argv.color)
318
- console.error("\u001b[1m\u001b[31m" + e.message + "\u001b[39m\u001b[22m");
319
- else
320
- console.error(e.message);
321
- process.exit(1); // eslint-disable-line no-process-exit
322
- }
323
- throw e;
324
- }
296
+ ifArg("display-cached", function(bool) {
297
+ if(bool)
298
+ outputOptions.cached = true;
299
+ });
325
300
 
326
- if(argv.progress) {
327
- var ProgressPlugin = require("../lib/ProgressPlugin");
328
- compiler.apply(new ProgressPlugin({
329
- profile: argv.profile
330
- }));
331
- }
301
+ ifArg("display-cached-assets", function(bool) {
302
+ if(bool)
303
+ outputOptions.cachedAssets = true;
304
+ });
305
+
306
+ if(!outputOptions.exclude)
307
+ outputOptions.exclude = ["node_modules", "bower_components", "components"];
332
308
 
333
- function compilerCallback(err, stats) {
334
- if(!options.watch || err) {
335
- // Do not keep cache anymore
336
- compiler.purgeInputFileSystem();
309
+ if(argv["display-modules"]) {
310
+ outputOptions.maxModules = Infinity;
311
+ outputOptions.exclude = undefined;
312
+ outputOptions.modules = true;
313
+ }
337
314
  }
338
- if(err) {
339
- lastHash = null;
340
- console.error(err.stack || err);
341
- if(err.details) console.error(err.details);
342
- process.exit(1); // eslint-disable-line
315
+
316
+ ifArg("hide-modules", function(bool) {
317
+ if(bool) {
318
+ outputOptions.modules = false;
319
+ outputOptions.chunkModules = false;
320
+ }
321
+ });
322
+
323
+ var webpack = require("../lib/webpack.js");
324
+
325
+ Error.stackTraceLimit = 30;
326
+ var lastHash = null;
327
+ var compiler;
328
+ try {
329
+ compiler = webpack(options);
330
+ } catch(e) {
331
+ var WebpackOptionsValidationError = require("../lib/WebpackOptionsValidationError");
332
+ if(e instanceof WebpackOptionsValidationError) {
333
+ if(argv.color)
334
+ console.error("\u001b[1m\u001b[31m" + e.message + "\u001b[39m\u001b[22m");
335
+ else
336
+ console.error(e.message);
337
+ process.exit(1); // eslint-disable-line no-process-exit
338
+ }
339
+ throw e;
343
340
  }
344
- if(outputOptions.json) {
345
- process.stdout.write(JSON.stringify(stats.toJson(outputOptions), null, 2) + "\n");
346
- } else if(stats.hash !== lastHash) {
347
- lastHash = stats.hash;
348
- var statsString = stats.toString(outputOptions);
349
- if(statsString)
350
- process.stdout.write(statsString + "\n");
341
+
342
+ if(argv.progress) {
343
+ var ProgressPlugin = require("../lib/ProgressPlugin");
344
+ compiler.apply(new ProgressPlugin({
345
+ profile: argv.profile
346
+ }));
351
347
  }
352
- if(!options.watch && stats.hasErrors()) {
353
- process.on("exit", function() {
354
- process.exit(2); // eslint-disable-line
355
- });
348
+
349
+ function compilerCallback(err, stats) {
350
+ if(!options.watch || err) {
351
+ // Do not keep cache anymore
352
+ compiler.purgeInputFileSystem();
353
+ }
354
+ if(err) {
355
+ lastHash = null;
356
+ console.error(err.stack || err);
357
+ if(err.details) console.error(err.details);
358
+ process.exit(1); // eslint-disable-line
359
+ }
360
+ if(outputOptions.json) {
361
+ process.stdout.write(JSON.stringify(stats.toJson(outputOptions), null, 2) + "\n");
362
+ } else if(stats.hash !== lastHash) {
363
+ lastHash = stats.hash;
364
+ var statsString = stats.toString(outputOptions);
365
+ if(statsString)
366
+ process.stdout.write(statsString + "\n");
367
+ }
368
+ if(!options.watch && stats.hasErrors()) {
369
+ process.exitCode = 2;
370
+ }
356
371
  }
372
+ if(firstOptions.watch || options.watch) {
373
+ var watchOptions = firstOptions.watchOptions || firstOptions.watch || options.watch || {};
374
+ if(watchOptions.stdin) {
375
+ process.stdin.on("end", function() {
376
+ process.exit(); // eslint-disable-line
377
+ });
378
+ process.stdin.resume();
379
+ }
380
+ compiler.watch(watchOptions, compilerCallback);
381
+ console.log("\nWebpack is watching the files…\n");
382
+ } else
383
+ compiler.run(compilerCallback);
384
+
357
385
  }
358
- if(firstOptions.watch || options.watch) {
359
- var watchOptions = firstOptions.watchOptions || firstOptions.watch || options.watch || {};
360
- if(watchOptions.stdin) {
361
- process.stdin.on("end", function() {
362
- process.exit(0); // eslint-disable-line
363
- });
364
- process.stdin.resume();
365
- }
366
- compiler.watch(watchOptions, compilerCallback);
367
- console.log("\nWebpack is watching the files…\n");
368
- } else
369
- compiler.run(compilerCallback);
370
386
 
371
- }
387
+ processOptions(options);
372
388
 
373
- processOptions(options);
389
+ });
@@ -140,8 +140,13 @@ class ContextModule extends Module {
140
140
  this.addBlock(block);
141
141
  }
142
142
 
143
- } else {
143
+ } else if(this.async === "weak" || this.async === "async-weak") {
144
+
145
+ // we mark all dependencies as weak
146
+ dependencies.forEach(dep => dep.weak = true);
147
+ this.dependencies = dependencies;
144
148
 
149
+ } else {
145
150
  // if we are lazy create a new async dependency block per dependency
146
151
  // and add all blocks to this context
147
152
  dependencies.forEach((dep, idx) => {
@@ -198,6 +203,58 @@ module.exports = webpackContext;
198
203
  webpackContext.id = ${JSON.stringify(id)};`;
199
204
  }
200
205
 
206
+ getWeakSyncSource(dependencies, id) {
207
+ const map = this.getUserRequestMap(dependencies);
208
+ return `var map = ${JSON.stringify(map, null, "\t")};
209
+ function webpackContext(req) {
210
+ var id = webpackContextResolve(req);
211
+ if(!__webpack_require__.m[id])
212
+ throw new Error("Module '" + req + "' ('" + id + "') is not available (weak dependency)");
213
+ return __webpack_require__(id);
214
+ };
215
+ function webpackContextResolve(req) {
216
+ var id = map[req];
217
+ if(!(id + 1)) // check for number or string
218
+ throw new Error("Cannot find module '" + req + "'.");
219
+ return id;
220
+ };
221
+ webpackContext.keys = function webpackContextKeys() {
222
+ return Object.keys(map);
223
+ };
224
+ webpackContext.resolve = webpackContextResolve;
225
+ webpackContext.id = ${JSON.stringify(id)};
226
+ module.exports = webpackContext;`;
227
+ }
228
+
229
+ getAsyncWeakSource(dependencies, id) {
230
+ const map = this.getUserRequestMap(dependencies);
231
+
232
+ return `var map = ${JSON.stringify(map, null, "\t")};
233
+ function webpackAsyncContext(req) {
234
+ return webpackAsyncContextResolve(req).then(function(id) {
235
+ if(!__webpack_require__.m[id])
236
+ throw new Error("Module '" + req + "' ('" + id + "') is not available (weak dependency)");
237
+ return __webpack_require__(id);
238
+ });
239
+ };
240
+ function webpackAsyncContextResolve(req) {
241
+ // Here Promise.resolve().then() is used instead of new Promise() to prevent
242
+ // uncatched exception popping up in devtools
243
+ return Promise.resolve().then(function() {
244
+ var id = map[req];
245
+ if(!(id + 1)) // check for number or string
246
+ throw new Error("Cannot find module '" + req + "'.");
247
+ return id;
248
+ });
249
+ };
250
+ webpackAsyncContext.keys = function webpackAsyncContextKeys() {
251
+ return Object.keys(map);
252
+ };
253
+ webpackAsyncContext.resolve = webpackAsyncContextResolve;
254
+ webpackAsyncContext.id = ${JSON.stringify(id)};
255
+ module.exports = webpackAsyncContext;`;
256
+ }
257
+
201
258
  getEagerSource(dependencies, id) {
202
259
  const map = this.getUserRequestMap(dependencies);
203
260
  return `var map = ${JSON.stringify(map, null, "\t")};
@@ -205,20 +262,21 @@ function webpackAsyncContext(req) {
205
262
  return webpackAsyncContextResolve(req).then(__webpack_require__);
206
263
  };
207
264
  function webpackAsyncContextResolve(req) {
208
- return new Promise(function(resolve, reject) {
265
+ // Here Promise.resolve().then() is used instead of new Promise() to prevent
266
+ // uncatched exception popping up in devtools
267
+ return Promise.resolve().then(function() {
209
268
  var id = map[req];
210
269
  if(!(id + 1)) // check for number or string
211
- reject(new Error("Cannot find module '" + req + "'."));
212
- else
213
- resolve(id);
270
+ throw new Error("Cannot find module '" + req + "'.");
271
+ return id;
214
272
  });
215
273
  };
216
274
  webpackAsyncContext.keys = function webpackAsyncContextKeys() {
217
275
  return Object.keys(map);
218
276
  };
219
277
  webpackAsyncContext.resolve = webpackAsyncContextResolve;
220
- module.exports = webpackAsyncContext;
221
- webpackAsyncContext.id = ${JSON.stringify(id)};`;
278
+ webpackAsyncContext.id = ${JSON.stringify(id)};
279
+ module.exports = webpackAsyncContext;`;
222
280
  }
223
281
 
224
282
  getLazyOnceSource(block, dependencies, id, outputOptions, requestShortener) {
@@ -240,8 +298,8 @@ webpackAsyncContext.keys = function webpackAsyncContextKeys() {
240
298
  return Object.keys(map);
241
299
  };
242
300
  webpackAsyncContext.resolve = webpackAsyncContextResolve;
243
- module.exports = webpackAsyncContext;
244
- webpackAsyncContext.id = ${JSON.stringify(id)};`;
301
+ webpackAsyncContext.id = ${JSON.stringify(id)};
302
+ module.exports = webpackAsyncContext;`;
245
303
  }
246
304
 
247
305
  getLazySource(blocks, id) {
@@ -282,8 +340,8 @@ function webpackAsyncContext(req) {
282
340
  webpackAsyncContext.keys = function webpackAsyncContextKeys() {
283
341
  return Object.keys(map);
284
342
  };
285
- module.exports = webpackAsyncContext;
286
- webpackAsyncContext.id = ${JSON.stringify(id)};`;
343
+ webpackAsyncContext.id = ${JSON.stringify(id)};
344
+ module.exports = webpackAsyncContext;`;
287
345
  }
288
346
 
289
347
  getSourceForEmptyContext(id) {
@@ -298,7 +356,11 @@ webpackEmptyContext.id = ${JSON.stringify(id)};`;
298
356
 
299
357
  getSourceForEmptyAsyncContext(id) {
300
358
  return `function webpackEmptyAsyncContext(req) {
301
- return new Promise(function(resolve, reject) { reject(new Error("Cannot find module '" + req + "'.")); });
359
+ // Here Promise.resolve().then() is used instead of new Promise() to prevent
360
+ // uncatched exception popping up in devtools
361
+ return Promise.resolve().then(function() {
362
+ throw new Error("Cannot find module '" + req + "'.");
363
+ });
302
364
  }
303
365
  webpackEmptyAsyncContext.keys = function() { return []; };
304
366
  webpackEmptyAsyncContext.resolve = webpackEmptyAsyncContext;
@@ -318,13 +380,25 @@ webpackEmptyAsyncContext.id = ${JSON.stringify(id)};`;
318
380
  return this.getEagerSource(this.dependencies, this.id);
319
381
  }
320
382
  return this.getSourceForEmptyAsyncContext(this.id);
321
- } else if(asyncMode === "lazy-once") {
383
+ }
384
+ if(asyncMode === "lazy-once") {
322
385
  const block = this.blocks[0];
323
386
  if(block) {
324
387
  return this.getLazyOnceSource(block, block.dependencies, this.id, outputOptions, requestShortener);
325
388
  }
326
389
  return this.getSourceForEmptyAsyncContext(this.id);
327
390
  }
391
+ if(asyncMode === "async-weak") {
392
+ if(this.dependencies && this.dependencies.length > 0) {
393
+ return this.getAsyncWeakSource(this.dependencies, this.id);
394
+ }
395
+ return this.getSourceForEmptyAsyncContext(this.id);
396
+ }
397
+ if(asyncMode === "weak") {
398
+ if(this.dependencies && this.dependencies.length > 0) {
399
+ return this.getWeakSyncSource(this.dependencies, this.id);
400
+ }
401
+ }
328
402
  if(this.dependencies && this.dependencies.length > 0) {
329
403
  return this.getSyncSource(this.dependencies, this.id);
330
404
  }
@@ -9,20 +9,26 @@ const OriginalSource = require("webpack-sources").OriginalSource;
9
9
  const RawSource = require("webpack-sources").RawSource;
10
10
  const WebpackMissingModule = require("./dependencies/WebpackMissingModule");
11
11
  const DelegatedSourceDependency = require("./dependencies/DelegatedSourceDependency");
12
+ const DelegatedExportsDependency = require("./dependencies/DelegatedExportsDependency");
12
13
 
13
14
  class DelegatedModule extends Module {
14
- constructor(sourceRequest, data, type, userRequest) {
15
+ constructor(sourceRequest, data, type, userRequest, originalRequest) {
15
16
  super();
16
17
  this.sourceRequest = sourceRequest;
17
18
  this.request = data.id;
18
19
  this.meta = data.meta;
19
20
  this.type = type;
21
+ this.originalRequest = originalRequest;
20
22
  this.userRequest = userRequest;
21
23
  this.built = false;
22
24
  this.delegated = true;
23
25
  this.delegateData = data;
24
26
  }
25
27
 
28
+ libIdent(options) {
29
+ return typeof this.originalRequest === "string" ? this.originalRequest : this.originalRequest.libIdent(options);
30
+ }
31
+
26
32
  identifier() {
27
33
  return `delegated ${JSON.stringify(this.request)} from ${this.sourceRequest}`;
28
34
  }
@@ -38,10 +44,10 @@ class DelegatedModule extends Module {
38
44
  build(options, compilation, resolver, fs, callback) {
39
45
  this.built = true;
40
46
  this.builtTime = Date.now();
41
- this.usedExports = true;
42
- this.providedExports = this.delegateData.exports || true;
47
+ this.cacheable = true;
43
48
  this.dependencies.length = 0;
44
49
  this.addDependency(new DelegatedSourceDependency(this.sourceRequest));
50
+ this.addDependency(new DelegatedExportsDependency(this, this.delegateData.exports || true));
45
51
  callback();
46
52
  }
47
53
 
@@ -57,7 +63,7 @@ class DelegatedModule extends Module {
57
63
  if(!sourceModule) {
58
64
  str = WebpackMissingModule.moduleCode(this.sourceRequest);
59
65
  } else {
60
- str = `module.exports = (__webpack_require__(${sourceModule.id}))`;
66
+ str = `module.exports = (__webpack_require__(${JSON.stringify(sourceModule.id)}))`;
61
67
 
62
68
  switch(this.type) {
63
69
  case "require":
@@ -29,13 +29,14 @@ class DelegatedModuleFactoryPlugin {
29
29
  let resolved;
30
30
  if(innerRequest in this.options.content) {
31
31
  resolved = this.options.content[innerRequest];
32
- return callback(null, new DelegatedModule(this.options.source, resolved, this.options.type, innerRequest));
32
+ return callback(null, new DelegatedModule(this.options.source, resolved, this.options.type, innerRequest, request));
33
33
  }
34
34
  for(let i = 0; i < this.options.extensions.length; i++) {
35
- const requestPlusExt = innerRequest + this.options.extensions[i];
35
+ const extension = this.options.extensions[i];
36
+ const requestPlusExt = innerRequest + extension;
36
37
  if(requestPlusExt in this.options.content) {
37
38
  resolved = this.options.content[requestPlusExt];
38
- return callback(null, new DelegatedModule(this.options.source, resolved, this.options.type, requestPlusExt));
39
+ return callback(null, new DelegatedModule(this.options.source, resolved, this.options.type, requestPlusExt, request + extension));
39
40
  }
40
41
  }
41
42
  }
@@ -47,7 +48,7 @@ class DelegatedModuleFactoryPlugin {
47
48
  const request = module.libIdent(this.options);
48
49
  if(request && request in this.options.content) {
49
50
  const resolved = this.options.content[request];
50
- return new DelegatedModule(this.options.source, resolved, this.options.type, request);
51
+ return new DelegatedModule(this.options.source, resolved, this.options.type, request, module);
51
52
  }
52
53
  }
53
54
  return module;