webpack 4.8.2 → 4.9.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.
Files changed (57) hide show
  1. package/README.md +95 -52
  2. package/bin/webpack.js +128 -43
  3. package/lib/AmdMainTemplatePlugin.js +10 -0
  4. package/lib/AsyncDependencyToInitialChunkError.js +12 -2
  5. package/lib/BannerPlugin.js +115 -101
  6. package/lib/CaseSensitiveModulesWarning.js +20 -2
  7. package/lib/Chunk.js +1 -0
  8. package/lib/ChunkGroup.js +465 -465
  9. package/lib/ChunkRenderError.js +8 -0
  10. package/lib/ChunkTemplate.js +71 -71
  11. package/lib/Compilation.js +1 -1
  12. package/lib/Compiler.js +2 -1
  13. package/lib/ContextModule.js +8 -8
  14. package/lib/DllPlugin.js +3 -1
  15. package/lib/DllReferencePlugin.js +2 -1
  16. package/lib/Entrypoint.js +54 -54
  17. package/lib/EvalSourceMapDevToolModuleTemplatePlugin.js +115 -115
  18. package/lib/ExportPropertyMainTemplatePlugin.js +13 -0
  19. package/lib/Generator.js +52 -52
  20. package/lib/HotModuleReplacement.runtime.js +633 -633
  21. package/lib/JsonParser.js +2 -1
  22. package/lib/LibManifestPlugin.js +9 -0
  23. package/lib/LibraryTemplatePlugin.js +66 -33
  24. package/lib/MainTemplate.js +468 -468
  25. package/lib/Module.js +3 -3
  26. package/lib/ModuleDependencyError.js +12 -2
  27. package/lib/NormalModuleFactory.js +5 -3
  28. package/lib/Parser.js +27 -23
  29. package/lib/ProgressPlugin.js +1 -1
  30. package/lib/RecordIdsPlugin.js +3 -1
  31. package/lib/RuntimeTemplate.js +1 -1
  32. package/lib/SetVarMainTemplatePlugin.js +12 -0
  33. package/lib/SourceMapDevToolPlugin.js +11 -13
  34. package/lib/Template.js +289 -290
  35. package/lib/UmdMainTemplatePlugin.js +67 -32
  36. package/lib/WebpackError.js +8 -2
  37. package/lib/compareLocations.js +20 -0
  38. package/lib/debug/ProfilingPlugin.js +416 -416
  39. package/lib/dependencies/ContextDependencyHelpers.js +142 -142
  40. package/lib/dependencies/WebpackMissingModule.js +2 -2
  41. package/lib/optimize/RemoveEmptyChunksPlugin.js +42 -40
  42. package/lib/optimize/RuntimeChunkPlugin.js +9 -5
  43. package/lib/optimize/SplitChunksPlugin.js +195 -124
  44. package/lib/util/Queue.js +46 -46
  45. package/lib/util/SetHelpers.js +48 -48
  46. package/lib/util/SortableSet.js +106 -106
  47. package/lib/util/StackedSetMap.js +128 -128
  48. package/lib/util/cachedMerge.js +13 -0
  49. package/lib/util/identifier.js +5 -0
  50. package/lib/util/objectToMap.js +16 -16
  51. package/lib/wasm/WebAssemblyGenerator.js +280 -280
  52. package/lib/wasm/WebAssemblyParser.js +79 -79
  53. package/lib/web/JsonpMainTemplatePlugin.js +2 -2
  54. package/package.json +21 -17
  55. package/schemas/WebpackOptions.json +12 -1
  56. package/schemas/plugins/BannerPlugin.json +96 -85
  57. package/schemas/plugins/DllPlugin.json +4 -0
@@ -6,7 +6,15 @@
6
6
 
7
7
  const WebpackError = require("./WebpackError");
8
8
 
9
+ /** @typedef {import("./Chunk")} Chunk */
10
+
9
11
  class ChunkRenderError extends WebpackError {
12
+ /**
13
+ * Create a new ChunkRenderError
14
+ * @param {Chunk} chunk A chunk
15
+ * @param {string} file Related file
16
+ * @param {Error} error Original error
17
+ */
10
18
  constructor(chunk, file, error) {
11
19
  super();
12
20
 
@@ -1,71 +1,71 @@
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, SyncWaterfallHook, SyncHook } = require("tapable");
8
-
9
- /** @typedef {import("./ModuleTemplate")} ModuleTemplate */
10
- /** @typedef {import("./Chunk")} Chunk */
11
- /** @typedef {import("./Module")} Module} */
12
- /** @typedef {import("crypto").Hash} Hash */
13
-
14
- /**
15
- * @typedef {Object} RenderManifestOptions
16
- * @property {Chunk} chunk the chunk used to render
17
- * @property {Hash} hash
18
- * @property {string} fullHash
19
- * @property {TODO} outputOptions
20
- * @property {{javascript: ModuleTemplate, webassembly: ModuleTemplate}} moduleTemplates
21
- * @property {Map<TODO, TODO>} dependencyTemplates
22
- */
23
-
24
- module.exports = class ChunkTemplate extends Tapable {
25
- constructor(outputOptions) {
26
- super();
27
- this.outputOptions = outputOptions || {};
28
- this.hooks = {
29
- renderManifest: new SyncWaterfallHook(["result", "options"]),
30
- modules: new SyncWaterfallHook([
31
- "source",
32
- "chunk",
33
- "moduleTemplate",
34
- "dependencyTemplates"
35
- ]),
36
- render: new SyncWaterfallHook([
37
- "source",
38
- "chunk",
39
- "moduleTemplate",
40
- "dependencyTemplates"
41
- ]),
42
- renderWithEntry: new SyncWaterfallHook(["source", "chunk"]),
43
- hash: new SyncHook(["hash"]),
44
- hashForChunk: new SyncHook(["hash", "chunk"])
45
- };
46
- }
47
-
48
- /**
49
- *
50
- * @param {RenderManifestOptions} options render manifest options
51
- * @returns {TODO[]} returns render manifest
52
- */
53
- getRenderManifest(options) {
54
- const result = [];
55
-
56
- this.hooks.renderManifest.call(result, options);
57
-
58
- return result;
59
- }
60
-
61
- updateHash(hash) {
62
- hash.update("ChunkTemplate");
63
- hash.update("2");
64
- this.hooks.hash.call(hash);
65
- }
66
-
67
- updateHashForChunk(hash, chunk) {
68
- this.updateHash(hash);
69
- this.hooks.hashForChunk.call(hash, chunk);
70
- }
71
- };
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, SyncWaterfallHook, SyncHook } = require("tapable");
8
+
9
+ /** @typedef {import("./ModuleTemplate")} ModuleTemplate */
10
+ /** @typedef {import("./Chunk")} Chunk */
11
+ /** @typedef {import("./Module")} Module} */
12
+ /** @typedef {import("crypto").Hash} Hash */
13
+
14
+ /**
15
+ * @typedef {Object} RenderManifestOptions
16
+ * @property {Chunk} chunk the chunk used to render
17
+ * @property {Hash} hash
18
+ * @property {string} fullHash
19
+ * @property {TODO} outputOptions
20
+ * @property {{javascript: ModuleTemplate, webassembly: ModuleTemplate}} moduleTemplates
21
+ * @property {Map<TODO, TODO>} dependencyTemplates
22
+ */
23
+
24
+ module.exports = class ChunkTemplate extends Tapable {
25
+ constructor(outputOptions) {
26
+ super();
27
+ this.outputOptions = outputOptions || {};
28
+ this.hooks = {
29
+ renderManifest: new SyncWaterfallHook(["result", "options"]),
30
+ modules: new SyncWaterfallHook([
31
+ "source",
32
+ "chunk",
33
+ "moduleTemplate",
34
+ "dependencyTemplates"
35
+ ]),
36
+ render: new SyncWaterfallHook([
37
+ "source",
38
+ "chunk",
39
+ "moduleTemplate",
40
+ "dependencyTemplates"
41
+ ]),
42
+ renderWithEntry: new SyncWaterfallHook(["source", "chunk"]),
43
+ hash: new SyncHook(["hash"]),
44
+ hashForChunk: new SyncHook(["hash", "chunk"])
45
+ };
46
+ }
47
+
48
+ /**
49
+ *
50
+ * @param {RenderManifestOptions} options render manifest options
51
+ * @returns {TODO[]} returns render manifest
52
+ */
53
+ getRenderManifest(options) {
54
+ const result = [];
55
+
56
+ this.hooks.renderManifest.call(result, options);
57
+
58
+ return result;
59
+ }
60
+
61
+ updateHash(hash) {
62
+ hash.update("ChunkTemplate");
63
+ hash.update("2");
64
+ this.hooks.hash.call(hash);
65
+ }
66
+
67
+ updateHashForChunk(hash, chunk) {
68
+ this.updateHash(hash);
69
+ this.hooks.hashForChunk.call(hash, chunk);
70
+ }
71
+ };
@@ -865,7 +865,7 @@ class Compilation extends Tapable {
865
865
  this.assignIndex(module);
866
866
  this.assignDepth(module);
867
867
  }
868
- this.processDependenciesBlocksForChunkGroups(this.chunkGroups);
868
+ this.processDependenciesBlocksForChunkGroups(this.chunkGroups.slice());
869
869
  this.sortModules(this.modules);
870
870
  this.hooks.optimize.call();
871
871
 
package/lib/Compiler.js CHANGED
@@ -4,6 +4,7 @@
4
4
  */
5
5
  "use strict";
6
6
 
7
+ const parseJson = require("json-parse-better-errors");
7
8
  const asyncLib = require("neo-async");
8
9
  const path = require("path");
9
10
  const util = require("util");
@@ -350,7 +351,7 @@ class Compiler extends Tapable {
350
351
  if (err) return callback(err);
351
352
 
352
353
  try {
353
- this.records = JSON.parse(content.toString("utf-8"));
354
+ this.records = parseJson(content.toString("utf-8"));
354
355
  } catch (e) {
355
356
  e.message = "Cannot parse records: " + e.message;
356
357
  return callback(e);
@@ -330,7 +330,7 @@ function webpackContext(req) {
330
330
  function webpackContextResolve(req) {
331
331
  var id = map[req];
332
332
  if(!(id + 1)) { // check for number or string
333
- var e = new Error('Cannot find module "' + req + '".');
333
+ var e = new Error("Cannot find module '" + req + "'");
334
334
  e.code = 'MODULE_NOT_FOUND';
335
335
  throw e;
336
336
  }
@@ -365,7 +365,7 @@ function webpackContext(req) {
365
365
  function webpackContextResolve(req) {
366
366
  var id = map[req];
367
367
  if(!(id + 1)) { // check for number or string
368
- var e = new Error('Cannot find module "' + req + '".');
368
+ var e = new Error("Cannot find module '" + req + "'");
369
369
  e.code = 'MODULE_NOT_FOUND';
370
370
  throw e;
371
371
  }
@@ -404,7 +404,7 @@ function webpackAsyncContextResolve(req) {
404
404
  return Promise.resolve().then(function() {
405
405
  var id = map[req];
406
406
  if(!(id + 1)) { // check for number or string
407
- var e = new Error('Cannot find module "' + req + '".');
407
+ var e = new Error("Cannot find module '" + req + "'");
408
408
  e.code = 'MODULE_NOT_FOUND';
409
409
  throw e;
410
410
  }
@@ -441,7 +441,7 @@ function webpackAsyncContextResolve(req) {
441
441
  return Promise.resolve().then(function() {
442
442
  var id = map[req];
443
443
  if(!(id + 1)) { // check for number or string
444
- var e = new Error('Cannot find module "' + req + '".');
444
+ var e = new Error("Cannot find module '" + req + "'");
445
445
  e.code = 'MODULE_NOT_FOUND';
446
446
  throw e;
447
447
  }
@@ -481,7 +481,7 @@ function webpackAsyncContextResolve(req) {
481
481
  return ${promise}.then(function() {
482
482
  var id = map[req];
483
483
  if(!(id + 1)) { // check for number or string
484
- var e = new Error('Cannot find module "' + req + '".');
484
+ var e = new Error("Cannot find module '" + req + "'");
485
485
  e.code = 'MODULE_NOT_FOUND';
486
486
  throw e;
487
487
  }
@@ -540,7 +540,7 @@ function webpackAsyncContext(req) {
540
540
  var ids = map[req];
541
541
  if(!ids) {
542
542
  return Promise.resolve().then(function() {
543
- var e = new Error('Cannot find module "' + req + '".');
543
+ var e = new Error("Cannot find module '" + req + "'");
544
544
  e.code = 'MODULE_NOT_FOUND';
545
545
  throw e;
546
546
  });
@@ -559,7 +559,7 @@ module.exports = webpackAsyncContext;`;
559
559
 
560
560
  getSourceForEmptyContext(id) {
561
561
  return `function webpackEmptyContext(req) {
562
- var e = new Error('Cannot find module "' + req + '".');
562
+ var e = new Error("Cannot find module '" + req + "'");
563
563
  e.code = 'MODULE_NOT_FOUND';
564
564
  throw e;
565
565
  }
@@ -574,7 +574,7 @@ webpackEmptyContext.id = ${JSON.stringify(id)};`;
574
574
  // Here Promise.resolve().then() is used instead of new Promise() to prevent
575
575
  // uncaught exception popping up in devtools
576
576
  return Promise.resolve().then(function() {
577
- var e = new Error('Cannot find module "' + req + '".');
577
+ var e = new Error("Cannot find module '" + req + "'");
578
578
  e.code = 'MODULE_NOT_FOUND';
579
579
  throw e;
580
580
  });
package/lib/DllPlugin.js CHANGED
@@ -33,7 +33,9 @@ class DllPlugin {
33
33
  return true;
34
34
  });
35
35
  new LibManifestPlugin(this.options).apply(compiler);
36
- new FlagInitialModulesAsUsedPlugin("DllPlugin").apply(compiler);
36
+ if (!this.options.entryOnly) {
37
+ new FlagInitialModulesAsUsedPlugin("DllPlugin").apply(compiler);
38
+ }
37
39
  }
38
40
  }
39
41
 
@@ -4,6 +4,7 @@
4
4
  */
5
5
  "use strict";
6
6
 
7
+ const parseJson = require("json-parse-better-errors");
7
8
  const DelegatedSourceDependency = require("./dependencies/DelegatedSourceDependency");
8
9
  const DelegatedModuleFactoryPlugin = require("./DelegatedModuleFactoryPlugin");
9
10
  const ExternalModuleFactoryPlugin = require("./ExternalModuleFactoryPlugin");
@@ -42,7 +43,7 @@ class DllReferencePlugin {
42
43
  params.compilationDependencies.add(manifest);
43
44
  compiler.inputFileSystem.readFile(manifest, (err, result) => {
44
45
  if (err) return callback(err);
45
- params["dll reference " + manifest] = JSON.parse(
46
+ params["dll reference " + manifest] = parseJson(
46
47
  result.toString("utf-8")
47
48
  );
48
49
  return callback();
package/lib/Entrypoint.js CHANGED
@@ -1,54 +1,54 @@
1
- /*
2
- MIT License http://www.opensource.org/licenses/mit-license.php
3
- Author Tobias Koppers @sokra
4
- */
5
- "use strict";
6
-
7
- const ChunkGroup = require("./ChunkGroup");
8
-
9
- /** @typedef {import("./Chunk.js")} Chunk */
10
-
11
- /**
12
- * Entrypoint serves as an encapsulation primitive for chunks that are
13
- * a part of a single ChunkGroup. They represent all bundles that need to be loaded for a
14
- * single instance of a page. Multi-page application architectures will typically yield multiple Entrypoint objects
15
- * inside of the compilation, whereas a Single Page App may only contain one with many lazy-loaded chunks.
16
- */
17
- class Entrypoint extends ChunkGroup {
18
- /**
19
- * Creates an instance of Entrypoint.
20
- * @param {string} name the name of the entrypoint
21
- */
22
- constructor(name) {
23
- super(name);
24
- /** @type {Chunk=} */
25
- this.runtimeChunk = undefined;
26
- }
27
-
28
- /**
29
- * isInitial will always return true for Entrypoint ChunkGroup.
30
- * @returns {true} returns true as all entrypoints are initial ChunkGroups
31
- */
32
- isInitial() {
33
- return true;
34
- }
35
-
36
- /**
37
- * Sets the runtimeChunk for an entrypoint.
38
- * @param {Chunk} chunk the chunk being set as the runtime chunk.
39
- * @returns {void}
40
- */
41
- setRuntimeChunk(chunk) {
42
- this.runtimeChunk = chunk;
43
- }
44
-
45
- /**
46
- * Fetches the chunk reference containing the webpack bootstrap code
47
- * @returns {Chunk} returns the runtime chunk or first chunk in `this.chunks`
48
- */
49
- getRuntimeChunk() {
50
- return this.runtimeChunk || this.chunks[0];
51
- }
52
- }
53
-
54
- module.exports = Entrypoint;
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Tobias Koppers @sokra
4
+ */
5
+ "use strict";
6
+
7
+ const ChunkGroup = require("./ChunkGroup");
8
+
9
+ /** @typedef {import("./Chunk.js")} Chunk */
10
+
11
+ /**
12
+ * Entrypoint serves as an encapsulation primitive for chunks that are
13
+ * a part of a single ChunkGroup. They represent all bundles that need to be loaded for a
14
+ * single instance of a page. Multi-page application architectures will typically yield multiple Entrypoint objects
15
+ * inside of the compilation, whereas a Single Page App may only contain one with many lazy-loaded chunks.
16
+ */
17
+ class Entrypoint extends ChunkGroup {
18
+ /**
19
+ * Creates an instance of Entrypoint.
20
+ * @param {string} name the name of the entrypoint
21
+ */
22
+ constructor(name) {
23
+ super(name);
24
+ /** @type {Chunk=} */
25
+ this.runtimeChunk = undefined;
26
+ }
27
+
28
+ /**
29
+ * isInitial will always return true for Entrypoint ChunkGroup.
30
+ * @returns {true} returns true as all entrypoints are initial ChunkGroups
31
+ */
32
+ isInitial() {
33
+ return true;
34
+ }
35
+
36
+ /**
37
+ * Sets the runtimeChunk for an entrypoint.
38
+ * @param {Chunk} chunk the chunk being set as the runtime chunk.
39
+ * @returns {void}
40
+ */
41
+ setRuntimeChunk(chunk) {
42
+ this.runtimeChunk = chunk;
43
+ }
44
+
45
+ /**
46
+ * Fetches the chunk reference containing the webpack bootstrap code
47
+ * @returns {Chunk} returns the runtime chunk or first chunk in `this.chunks`
48
+ */
49
+ getRuntimeChunk() {
50
+ return this.runtimeChunk || this.chunks[0];
51
+ }
52
+ }
53
+
54
+ module.exports = Entrypoint;
@@ -1,115 +1,115 @@
1
- /*
2
- MIT License http://www.opensource.org/licenses/mit-license.php
3
- Author Tobias Koppers @sokra
4
- */
5
- "use strict";
6
-
7
- const { RawSource } = require("webpack-sources");
8
- const ModuleFilenameHelpers = require("./ModuleFilenameHelpers");
9
-
10
- const cache = new WeakMap();
11
-
12
- class EvalSourceMapDevToolModuleTemplatePlugin {
13
- constructor(compilation, options) {
14
- this.compilation = compilation;
15
- this.sourceMapComment =
16
- options.append || "//# sourceURL=[module]\n//# sourceMappingURL=[url]";
17
- this.moduleFilenameTemplate =
18
- options.moduleFilenameTemplate ||
19
- "webpack://[namespace]/[resource-path]?[hash]";
20
- this.namespace = options.namespace || "";
21
- this.options = options;
22
- }
23
-
24
- apply(moduleTemplate) {
25
- const self = this;
26
- const options = this.options;
27
- const matchModule = ModuleFilenameHelpers.matchObject.bind(
28
- ModuleFilenameHelpers,
29
- options
30
- );
31
- moduleTemplate.hooks.module.tap(
32
- "EvalSourceMapDevToolModuleTemplatePlugin",
33
- (source, module) => {
34
- const cachedSource = cache.get(source);
35
- if (cachedSource !== undefined) {
36
- return cachedSource;
37
- }
38
-
39
- if (!matchModule(module.resource)) {
40
- return source;
41
- }
42
-
43
- /** @type {{ [key: string]: TODO; }} */
44
- let sourceMap;
45
- let content;
46
- if (source.sourceAndMap) {
47
- const sourceAndMap = source.sourceAndMap(options);
48
- sourceMap = sourceAndMap.map;
49
- content = sourceAndMap.source;
50
- } else {
51
- sourceMap = source.map(options);
52
- content = source.source();
53
- }
54
- if (!sourceMap) {
55
- return source;
56
- }
57
-
58
- // Clone (flat) the sourcemap to ensure that the mutations below do not persist.
59
- sourceMap = Object.keys(sourceMap).reduce((obj, key) => {
60
- obj[key] = sourceMap[key];
61
- return obj;
62
- }, {});
63
- const modules = sourceMap.sources.map(source => {
64
- const module = self.compilation.findModule(source);
65
- return module || source;
66
- });
67
- let moduleFilenames = modules.map(module => {
68
- return ModuleFilenameHelpers.createFilename(
69
- module,
70
- {
71
- moduleFilenameTemplate: self.moduleFilenameTemplate,
72
- namespace: self.namespace
73
- },
74
- moduleTemplate.runtimeTemplate.requestShortener
75
- );
76
- });
77
- moduleFilenames = ModuleFilenameHelpers.replaceDuplicates(
78
- moduleFilenames,
79
- (filename, i, n) => {
80
- for (let j = 0; j < n; j++) filename += "*";
81
- return filename;
82
- }
83
- );
84
- sourceMap.sources = moduleFilenames;
85
- sourceMap.sourceRoot = options.sourceRoot || "";
86
- sourceMap.file = `${module.id}.js`;
87
-
88
- const footer =
89
- self.sourceMapComment.replace(
90
- /\[url\]/g,
91
- `data:application/json;charset=utf-8;base64,${Buffer.from(
92
- JSON.stringify(sourceMap),
93
- "utf8"
94
- ).toString("base64")}`
95
- ) + `\n//# sourceURL=webpack-internal:///${module.id}\n`; // workaround for chrome bug
96
-
97
- const evalSource = new RawSource(
98
- `eval(${JSON.stringify(content + footer)});`
99
- );
100
-
101
- cache.set(source, evalSource);
102
-
103
- return evalSource;
104
- }
105
- );
106
- moduleTemplate.hooks.hash.tap(
107
- "EvalSourceMapDevToolModuleTemplatePlugin",
108
- hash => {
109
- hash.update("eval-source-map");
110
- hash.update("2");
111
- }
112
- );
113
- }
114
- }
115
- module.exports = EvalSourceMapDevToolModuleTemplatePlugin;
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Tobias Koppers @sokra
4
+ */
5
+ "use strict";
6
+
7
+ const { RawSource } = require("webpack-sources");
8
+ const ModuleFilenameHelpers = require("./ModuleFilenameHelpers");
9
+
10
+ const cache = new WeakMap();
11
+
12
+ class EvalSourceMapDevToolModuleTemplatePlugin {
13
+ constructor(compilation, options) {
14
+ this.compilation = compilation;
15
+ this.sourceMapComment =
16
+ options.append || "//# sourceURL=[module]\n//# sourceMappingURL=[url]";
17
+ this.moduleFilenameTemplate =
18
+ options.moduleFilenameTemplate ||
19
+ "webpack://[namespace]/[resource-path]?[hash]";
20
+ this.namespace = options.namespace || "";
21
+ this.options = options;
22
+ }
23
+
24
+ apply(moduleTemplate) {
25
+ const self = this;
26
+ const options = this.options;
27
+ const matchModule = ModuleFilenameHelpers.matchObject.bind(
28
+ ModuleFilenameHelpers,
29
+ options
30
+ );
31
+ moduleTemplate.hooks.module.tap(
32
+ "EvalSourceMapDevToolModuleTemplatePlugin",
33
+ (source, module) => {
34
+ const cachedSource = cache.get(source);
35
+ if (cachedSource !== undefined) {
36
+ return cachedSource;
37
+ }
38
+
39
+ if (!matchModule(module.resource)) {
40
+ return source;
41
+ }
42
+
43
+ /** @type {{ [key: string]: TODO; }} */
44
+ let sourceMap;
45
+ let content;
46
+ if (source.sourceAndMap) {
47
+ const sourceAndMap = source.sourceAndMap(options);
48
+ sourceMap = sourceAndMap.map;
49
+ content = sourceAndMap.source;
50
+ } else {
51
+ sourceMap = source.map(options);
52
+ content = source.source();
53
+ }
54
+ if (!sourceMap) {
55
+ return source;
56
+ }
57
+
58
+ // Clone (flat) the sourcemap to ensure that the mutations below do not persist.
59
+ sourceMap = Object.keys(sourceMap).reduce((obj, key) => {
60
+ obj[key] = sourceMap[key];
61
+ return obj;
62
+ }, {});
63
+ const modules = sourceMap.sources.map(source => {
64
+ const module = self.compilation.findModule(source);
65
+ return module || source;
66
+ });
67
+ let moduleFilenames = modules.map(module => {
68
+ return ModuleFilenameHelpers.createFilename(
69
+ module,
70
+ {
71
+ moduleFilenameTemplate: self.moduleFilenameTemplate,
72
+ namespace: self.namespace
73
+ },
74
+ moduleTemplate.runtimeTemplate.requestShortener
75
+ );
76
+ });
77
+ moduleFilenames = ModuleFilenameHelpers.replaceDuplicates(
78
+ moduleFilenames,
79
+ (filename, i, n) => {
80
+ for (let j = 0; j < n; j++) filename += "*";
81
+ return filename;
82
+ }
83
+ );
84
+ sourceMap.sources = moduleFilenames;
85
+ sourceMap.sourceRoot = options.sourceRoot || "";
86
+ sourceMap.file = `${module.id}.js`;
87
+
88
+ const footer =
89
+ self.sourceMapComment.replace(
90
+ /\[url\]/g,
91
+ `data:application/json;charset=utf-8;base64,${Buffer.from(
92
+ JSON.stringify(sourceMap),
93
+ "utf8"
94
+ ).toString("base64")}`
95
+ ) + `\n//# sourceURL=webpack-internal:///${module.id}\n`; // workaround for chrome bug
96
+
97
+ const evalSource = new RawSource(
98
+ `eval(${JSON.stringify(content + footer)});`
99
+ );
100
+
101
+ cache.set(source, evalSource);
102
+
103
+ return evalSource;
104
+ }
105
+ );
106
+ moduleTemplate.hooks.hash.tap(
107
+ "EvalSourceMapDevToolModuleTemplatePlugin",
108
+ hash => {
109
+ hash.update("eval-source-map");
110
+ hash.update("2");
111
+ }
112
+ );
113
+ }
114
+ }
115
+ module.exports = EvalSourceMapDevToolModuleTemplatePlugin;
@@ -6,15 +6,28 @@
6
6
 
7
7
  const { ConcatSource } = require("webpack-sources");
8
8
 
9
+ /** @typedef {import("./Compilation")} Compilation */
10
+
11
+ /**
12
+ * @param {string[]} accessor the accessor to convert to path
13
+ * @returns {string} the path
14
+ */
9
15
  const accessorToObjectAccess = accessor => {
10
16
  return accessor.map(a => `[${JSON.stringify(a)}]`).join("");
11
17
  };
12
18
 
13
19
  class ExportPropertyMainTemplatePlugin {
20
+ /**
21
+ * @param {string|string[]} property the name of the property to export
22
+ */
14
23
  constructor(property) {
15
24
  this.property = property;
16
25
  }
17
26
 
27
+ /**
28
+ * @param {Compilation} compilation the compilation instance
29
+ * @returns {void}
30
+ */
18
31
  apply(compilation) {
19
32
  const { mainTemplate, chunkTemplate } = compilation;
20
33