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,52 +1,51 @@
1
- /*
2
- MIT License http://www.opensource.org/licenses/mit-license.php
3
- Author Tobias Koppers @sokra
4
- */
5
- "use strict";
6
-
7
- const ReplaceSource = require("webpack-sources").ReplaceSource;
8
- const RawSource = require("webpack-sources").RawSource;
9
-
10
- class DependenciesBlockVariable {
11
- constructor(name, expression, dependencies) {
12
- this.name = name;
13
- this.expression = expression;
14
- this.dependencies = dependencies || [];
15
- }
16
-
17
- updateHash(hash) {
18
- hash.update(this.name);
19
- hash.update(this.expression);
20
- for (const d of this.dependencies) {
21
- d.updateHash(hash);
22
- }
23
- }
24
-
25
- expressionSource(dependencyTemplates, runtimeTemplate) {
26
- const source = new ReplaceSource(new RawSource(this.expression));
27
- for (const dep of this.dependencies) {
28
- const template = dependencyTemplates.get(dep.constructor);
29
- if (!template)
30
- throw new Error(`No template for dependency: ${dep.constructor.name}`);
31
- template.apply(dep, source, runtimeTemplate, dependencyTemplates);
32
- }
33
- return source;
34
- }
35
-
36
- disconnect() {
37
- for (const d of this.dependencies) {
38
- d.disconnect();
39
- }
40
- }
41
-
42
- hasDependencies(filter) {
43
- if (filter) {
44
- if (this.dependencies.some(filter)) return true;
45
- } else {
46
- if (this.dependencies.length > 0) return true;
47
- }
48
- return false;
49
- }
50
- }
51
-
52
- module.exports = DependenciesBlockVariable;
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, ReplaceSource } = require("webpack-sources");
8
+
9
+ class DependenciesBlockVariable {
10
+ constructor(name, expression, dependencies) {
11
+ this.name = name;
12
+ this.expression = expression;
13
+ this.dependencies = dependencies || [];
14
+ }
15
+
16
+ updateHash(hash) {
17
+ hash.update(this.name);
18
+ hash.update(this.expression);
19
+ for (const d of this.dependencies) {
20
+ d.updateHash(hash);
21
+ }
22
+ }
23
+
24
+ expressionSource(dependencyTemplates, runtimeTemplate) {
25
+ const source = new ReplaceSource(new RawSource(this.expression));
26
+ for (const dep of this.dependencies) {
27
+ const template = dependencyTemplates.get(dep.constructor);
28
+ if (!template)
29
+ throw new Error(`No template for dependency: ${dep.constructor.name}`);
30
+ template.apply(dep, source, runtimeTemplate, dependencyTemplates);
31
+ }
32
+ return source;
33
+ }
34
+
35
+ disconnect() {
36
+ for (const d of this.dependencies) {
37
+ d.disconnect();
38
+ }
39
+ }
40
+
41
+ hasDependencies(filter) {
42
+ if (filter) {
43
+ if (this.dependencies.some(filter)) return true;
44
+ } else {
45
+ if (this.dependencies.length > 0) return true;
46
+ }
47
+ return false;
48
+ }
49
+ }
50
+
51
+ module.exports = DependenciesBlockVariable;
package/lib/Dependency.js CHANGED
@@ -1,52 +1,53 @@
1
- /*
2
- MIT License http://www.opensource.org/licenses/mit-license.php
3
- Author Tobias Koppers @sokra
4
- */
5
- "use strict";
6
- const compareLocations = require("./compareLocations");
7
-
8
- class Dependency {
9
- constructor() {
10
- this.module = null;
11
- this.weak = false;
12
- this.optional = false;
13
- }
14
-
15
- getResourceIdentifier() {
16
- return null;
17
- }
18
-
19
- // Returns the referenced module and export
20
- getReference() {
21
- if (!this.module) return null;
22
- return {
23
- module: this.module,
24
- weak: this.weak,
25
- importedNames: true // true: full object, false: only sideeffects/no export, array of strings: the exports with this names
26
- };
27
- }
28
-
29
- // Returns the exported names
30
- getExports() {
31
- return null;
32
- }
33
-
34
- getWarnings() {
35
- return null;
36
- }
37
-
38
- getErrors() {
39
- return null;
40
- }
41
-
42
- updateHash(hash) {
43
- hash.update((this.module && this.module.id) + "");
44
- }
45
-
46
- disconnect() {
47
- this.module = null;
48
- }
49
- }
50
- Dependency.compare = (a, b) => compareLocations(a.loc, b.loc);
51
-
52
- module.exports = Dependency;
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Tobias Koppers @sokra
4
+ */
5
+ "use strict";
6
+ const compareLocations = require("./compareLocations");
7
+
8
+ class Dependency {
9
+ constructor() {
10
+ this.module = null;
11
+ this.weak = false;
12
+ this.optional = false;
13
+ this.loc = undefined;
14
+ }
15
+
16
+ getResourceIdentifier() {
17
+ return null;
18
+ }
19
+
20
+ // Returns the referenced module and export
21
+ getReference() {
22
+ if (!this.module) return null;
23
+ return {
24
+ module: this.module,
25
+ weak: this.weak,
26
+ importedNames: true // true: full object, false: only sideeffects/no export, array of strings: the exports with this names
27
+ };
28
+ }
29
+
30
+ // Returns the exported names
31
+ getExports() {
32
+ return null;
33
+ }
34
+
35
+ getWarnings() {
36
+ return null;
37
+ }
38
+
39
+ getErrors() {
40
+ return null;
41
+ }
42
+
43
+ updateHash(hash) {
44
+ hash.update((this.module && this.module.id) + "");
45
+ }
46
+
47
+ disconnect() {
48
+ this.module = null;
49
+ }
50
+ }
51
+ Dependency.compare = (a, b) => compareLocations(a.loc, b.loc);
52
+
53
+ module.exports = Dependency;
package/lib/DllModule.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 Module = require("./Module");
8
- const RawSource = require("webpack-sources").RawSource;
9
-
10
- class DllModule extends Module {
11
- constructor(context, dependencies, name, type) {
12
- super("javascript/dynamic", context);
13
-
14
- // Info from Factory
15
- this.dependencies = dependencies;
16
- this.name = name;
17
- this.type = type;
18
- }
19
-
20
- identifier() {
21
- return `dll ${this.name}`;
22
- }
23
-
24
- readableIdentifier() {
25
- return `dll ${this.name}`;
26
- }
27
-
28
- build(options, compilation, resolver, fs, callback) {
29
- this.built = true;
30
- this.buildMeta = {};
31
- this.buildInfo = {};
32
- return callback();
33
- }
34
-
35
- source() {
36
- return new RawSource("module.exports = __webpack_require__;");
37
- }
38
-
39
- needRebuild() {
40
- return false;
41
- }
42
-
43
- size() {
44
- return 12;
45
- }
46
-
47
- updateHash(hash) {
48
- hash.update("dll module");
49
- hash.update(this.name || "");
50
- super.updateHash(hash);
51
- }
52
- }
53
-
54
- module.exports = DllModule;
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 Module = require("./Module");
9
+
10
+ class DllModule extends Module {
11
+ constructor(context, dependencies, name, type) {
12
+ super("javascript/dynamic", context);
13
+
14
+ // Info from Factory
15
+ this.dependencies = dependencies;
16
+ this.name = name;
17
+ this.type = type;
18
+ }
19
+
20
+ identifier() {
21
+ return `dll ${this.name}`;
22
+ }
23
+
24
+ readableIdentifier() {
25
+ return `dll ${this.name}`;
26
+ }
27
+
28
+ build(options, compilation, resolver, fs, callback) {
29
+ this.built = true;
30
+ this.buildMeta = {};
31
+ this.buildInfo = {};
32
+ return callback();
33
+ }
34
+
35
+ source() {
36
+ return new RawSource("module.exports = __webpack_require__;");
37
+ }
38
+
39
+ needRebuild() {
40
+ return false;
41
+ }
42
+
43
+ size() {
44
+ return 12;
45
+ }
46
+
47
+ updateHash(hash) {
48
+ hash.update("dll module");
49
+ hash.update(this.name || "");
50
+ super.updateHash(hash);
51
+ }
52
+ }
53
+
54
+ module.exports = DllModule;
@@ -1,29 +1,29 @@
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 DllModule = require("./DllModule");
9
-
10
- class DllModuleFactory extends Tapable {
11
- constructor() {
12
- super();
13
- this.hooks = {};
14
- }
15
- create(data, callback) {
16
- const dependency = data.dependencies[0];
17
- callback(
18
- null,
19
- new DllModule(
20
- data.context,
21
- dependency.dependencies,
22
- dependency.name,
23
- dependency.type
24
- )
25
- );
26
- }
27
- }
28
-
29
- module.exports = DllModuleFactory;
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");
8
+ const DllModule = require("./DllModule");
9
+
10
+ class DllModuleFactory extends Tapable {
11
+ constructor() {
12
+ super();
13
+ this.hooks = {};
14
+ }
15
+ create(data, callback) {
16
+ const dependency = data.dependencies[0];
17
+ callback(
18
+ null,
19
+ new DllModule(
20
+ data.context,
21
+ dependency.dependencies,
22
+ dependency.name,
23
+ dependency.type
24
+ )
25
+ );
26
+ }
27
+ }
28
+
29
+ module.exports = DllModuleFactory;
@@ -1,67 +1,65 @@
1
- /*
2
- MIT License http://www.opensource.org/licenses/mit-license.php
3
- Authors Simen Brekken @simenbrekken, Einar Löve @einarlove
4
- */
5
-
6
- "use strict";
7
-
8
- const DefinePlugin = require("./DefinePlugin");
9
-
10
- const needsEnvVarFix =
11
- ["8", "9"].indexOf(process.versions.node.split(".")[0]) >= 0 &&
12
- process.platform === "win32";
13
-
14
- class EnvironmentPlugin {
15
- constructor(...keys) {
16
- if (keys.length === 1 && Array.isArray(keys[0])) {
17
- this.keys = keys[0];
18
- this.defaultValues = {};
19
- } else if (keys.length === 1 && keys[0] && typeof keys[0] === "object") {
20
- this.keys = Object.keys(keys[0]);
21
- this.defaultValues = keys[0];
22
- } else {
23
- this.keys = keys;
24
- this.defaultValues = {};
25
- }
26
- }
27
-
28
- apply(compiler) {
29
- const definitions = this.keys.reduce((defs, key) => {
30
- // TODO remove once the fix has made its way into Node 8.
31
- // Work around https://github.com/nodejs/node/pull/18463,
32
- // affecting Node 8 & 9 by performing an OS-level
33
- // operation that always succeeds before reading
34
- // environment variables:
35
- if (needsEnvVarFix) require("os").cpus();
36
-
37
- const value =
38
- process.env[key] !== undefined
39
- ? process.env[key]
40
- : this.defaultValues[key];
41
-
42
- if (value === undefined) {
43
- compiler.hooks.thisCompilation.tap("EnvironmentPlugin", compilation => {
44
- const error = new Error(
45
- `EnvironmentPlugin - ${
46
- key
47
- } environment variable is undefined.\n\n` +
48
- "You can pass an object with default values to suppress this warning.\n" +
49
- "See https://webpack.js.org/plugins/environment-plugin for example."
50
- );
51
-
52
- error.name = "EnvVariableNotDefinedError";
53
- compilation.warnings.push(error);
54
- });
55
- }
56
-
57
- defs[`process.env.${key}`] =
58
- typeof value === "undefined" ? "undefined" : JSON.stringify(value);
59
-
60
- return defs;
61
- }, {});
62
-
63
- new DefinePlugin(definitions).apply(compiler);
64
- }
65
- }
66
-
67
- module.exports = EnvironmentPlugin;
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Authors Simen Brekken @simenbrekken, Einar Löve @einarlove
4
+ */
5
+
6
+ "use strict";
7
+
8
+ const DefinePlugin = require("./DefinePlugin");
9
+
10
+ const needsEnvVarFix =
11
+ ["8", "9"].indexOf(process.versions.node.split(".")[0]) >= 0 &&
12
+ process.platform === "win32";
13
+
14
+ class EnvironmentPlugin {
15
+ constructor(...keys) {
16
+ if (keys.length === 1 && Array.isArray(keys[0])) {
17
+ this.keys = keys[0];
18
+ this.defaultValues = {};
19
+ } else if (keys.length === 1 && keys[0] && typeof keys[0] === "object") {
20
+ this.keys = Object.keys(keys[0]);
21
+ this.defaultValues = keys[0];
22
+ } else {
23
+ this.keys = keys;
24
+ this.defaultValues = {};
25
+ }
26
+ }
27
+
28
+ apply(compiler) {
29
+ const definitions = this.keys.reduce((defs, key) => {
30
+ // TODO remove once the fix has made its way into Node 8.
31
+ // Work around https://github.com/nodejs/node/pull/18463,
32
+ // affecting Node 8 & 9 by performing an OS-level
33
+ // operation that always succeeds before reading
34
+ // environment variables:
35
+ if (needsEnvVarFix) require("os").cpus();
36
+
37
+ const value =
38
+ process.env[key] !== undefined
39
+ ? process.env[key]
40
+ : this.defaultValues[key];
41
+
42
+ if (value === undefined) {
43
+ compiler.hooks.thisCompilation.tap("EnvironmentPlugin", compilation => {
44
+ const error = new Error(
45
+ `EnvironmentPlugin - ${key} environment variable is undefined.\n\n` +
46
+ "You can pass an object with default values to suppress this warning.\n" +
47
+ "See https://webpack.js.org/plugins/environment-plugin for example."
48
+ );
49
+
50
+ error.name = "EnvVariableNotDefinedError";
51
+ compilation.warnings.push(error);
52
+ });
53
+ }
54
+
55
+ defs[`process.env.${key}`] =
56
+ typeof value === "undefined" ? "undefined" : JSON.stringify(value);
57
+
58
+ return defs;
59
+ }, {});
60
+
61
+ new DefinePlugin(definitions).apply(compiler);
62
+ }
63
+ }
64
+
65
+ module.exports = EnvironmentPlugin;
@@ -1,60 +1,60 @@
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").RawSource;
8
- const ModuleFilenameHelpers = require("./ModuleFilenameHelpers");
9
- const cache = new WeakMap();
10
-
11
- class EvalDevToolModuleTemplatePlugin {
12
- constructor(options) {
13
- this.sourceUrlComment = options.sourceUrlComment || "\n//# sourceURL=[url]";
14
- this.moduleFilenameTemplate =
15
- options.moduleFilenameTemplate ||
16
- "webpack://[namespace]/[resourcePath]?[loaders]";
17
- this.namespace = options.namespace || "";
18
- }
19
-
20
- apply(moduleTemplate) {
21
- moduleTemplate.hooks.module.tap(
22
- "EvalDevToolModuleTemplatePlugin",
23
- (source, module) => {
24
- const cacheEntry = cache.get(source);
25
- if (cacheEntry !== undefined) return cacheEntry;
26
- const content = source.source();
27
- const str = ModuleFilenameHelpers.createFilename(
28
- module,
29
- {
30
- moduleFilenameTemplate: this.moduleFilenameTemplate,
31
- namespace: this.namespace
32
- },
33
- moduleTemplate.runtimeTemplate.requestShortener
34
- );
35
- const footer =
36
- "\n" +
37
- this.sourceUrlComment.replace(
38
- /\[url\]/g,
39
- encodeURI(str)
40
- .replace(/%2F/g, "/")
41
- .replace(/%20/g, "_")
42
- .replace(/%5E/g, "^")
43
- .replace(/%5C/g, "\\")
44
- .replace(/^\//, "")
45
- );
46
- const result = new RawSource(
47
- `eval(${JSON.stringify(content + footer)});`
48
- );
49
- cache.set(source, result);
50
- return result;
51
- }
52
- );
53
- moduleTemplate.hooks.hash.tap("EvalDevToolModuleTemplatePlugin", hash => {
54
- hash.update("EvalDevToolModuleTemplatePlugin");
55
- hash.update("2");
56
- });
57
- }
58
- }
59
-
60
- module.exports = EvalDevToolModuleTemplatePlugin;
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
+ const cache = new WeakMap();
10
+
11
+ class EvalDevToolModuleTemplatePlugin {
12
+ constructor(options) {
13
+ this.sourceUrlComment = options.sourceUrlComment || "\n//# sourceURL=[url]";
14
+ this.moduleFilenameTemplate =
15
+ options.moduleFilenameTemplate ||
16
+ "webpack://[namespace]/[resourcePath]?[loaders]";
17
+ this.namespace = options.namespace || "";
18
+ }
19
+
20
+ apply(moduleTemplate) {
21
+ moduleTemplate.hooks.module.tap(
22
+ "EvalDevToolModuleTemplatePlugin",
23
+ (source, module) => {
24
+ const cacheEntry = cache.get(source);
25
+ if (cacheEntry !== undefined) return cacheEntry;
26
+ const content = source.source();
27
+ const str = ModuleFilenameHelpers.createFilename(
28
+ module,
29
+ {
30
+ moduleFilenameTemplate: this.moduleFilenameTemplate,
31
+ namespace: this.namespace
32
+ },
33
+ moduleTemplate.runtimeTemplate.requestShortener
34
+ );
35
+ const footer =
36
+ "\n" +
37
+ this.sourceUrlComment.replace(
38
+ /\[url\]/g,
39
+ encodeURI(str)
40
+ .replace(/%2F/g, "/")
41
+ .replace(/%20/g, "_")
42
+ .replace(/%5E/g, "^")
43
+ .replace(/%5C/g, "\\")
44
+ .replace(/^\//, "")
45
+ );
46
+ const result = new RawSource(
47
+ `eval(${JSON.stringify(content + footer)});`
48
+ );
49
+ cache.set(source, result);
50
+ return result;
51
+ }
52
+ );
53
+ moduleTemplate.hooks.hash.tap("EvalDevToolModuleTemplatePlugin", hash => {
54
+ hash.update("EvalDevToolModuleTemplatePlugin");
55
+ hash.update("2");
56
+ });
57
+ }
58
+ }
59
+
60
+ module.exports = EvalDevToolModuleTemplatePlugin;