webpack 5.64.2 → 5.66.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.

Potentially problematic release.


This version of webpack might be problematic. Click here for more details.

Files changed (84) hide show
  1. package/lib/CacheFacade.js +2 -9
  2. package/lib/Chunk.js +2 -0
  3. package/lib/Compilation.js +79 -38
  4. package/lib/Dependency.js +10 -0
  5. package/lib/DependencyTemplate.js +9 -0
  6. package/lib/ExternalModule.js +93 -53
  7. package/lib/Generator.js +2 -0
  8. package/lib/Module.js +24 -1
  9. package/lib/ModuleFilenameHelpers.js +5 -1
  10. package/lib/NormalModule.js +3 -1
  11. package/lib/RuntimeGlobals.js +11 -1
  12. package/lib/RuntimePlugin.js +25 -0
  13. package/lib/RuntimeTemplate.js +113 -2
  14. package/lib/Template.js +2 -1
  15. package/lib/WatchIgnorePlugin.js +14 -1
  16. package/lib/Watching.js +32 -18
  17. package/lib/WebpackOptionsApply.js +43 -2
  18. package/lib/asset/AssetGenerator.js +10 -7
  19. package/lib/asset/RawDataUrlModule.js +145 -0
  20. package/lib/config/browserslistTargetHandler.js +38 -1
  21. package/lib/config/defaults.js +60 -4
  22. package/lib/config/target.js +10 -0
  23. package/lib/container/ContainerEntryModule.js +4 -3
  24. package/lib/css/CssGenerator.js +106 -0
  25. package/lib/css/CssLoadingRuntimeModule.js +393 -0
  26. package/lib/css/CssModulesPlugin.js +444 -0
  27. package/lib/css/CssParser.js +618 -0
  28. package/lib/css/walkCssTokens.js +659 -0
  29. package/lib/dependencies/CssExportDependency.js +85 -0
  30. package/lib/dependencies/CssImportDependency.js +75 -0
  31. package/lib/dependencies/CssLocalIdentifierDependency.js +119 -0
  32. package/lib/dependencies/CssSelfLocalIdentifierDependency.js +101 -0
  33. package/lib/dependencies/CssUrlDependency.js +132 -0
  34. package/lib/dependencies/URLDependency.js +3 -8
  35. package/lib/esm/ModuleChunkFormatPlugin.js +74 -49
  36. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +1 -1
  37. package/lib/hmr/lazyCompilationBackend.js +3 -1
  38. package/lib/index.js +3 -0
  39. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +2 -2
  40. package/lib/javascript/ChunkHelpers.js +33 -0
  41. package/lib/javascript/JavascriptGenerator.js +1 -0
  42. package/lib/javascript/JavascriptParser.js +16 -8
  43. package/lib/javascript/StartupHelpers.js +4 -28
  44. package/lib/library/AssignLibraryPlugin.js +31 -13
  45. package/lib/library/EnableLibraryPlugin.js +11 -0
  46. package/lib/node/NodeWatchFileSystem.js +85 -31
  47. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +1 -1
  48. package/lib/node/RequireChunkLoadingRuntimeModule.js +1 -1
  49. package/lib/optimize/ConcatenatedModule.js +10 -4
  50. package/lib/sharing/ConsumeSharedModule.js +4 -0
  51. package/lib/sharing/ConsumeSharedRuntimeModule.js +25 -4
  52. package/lib/stats/DefaultStatsPrinterPlugin.js +1 -1
  53. package/lib/util/create-schema-validation.js +9 -2
  54. package/lib/util/extractUrlAndGlobal.js +3 -0
  55. package/lib/util/fs.js +10 -0
  56. package/lib/util/hash/xxhash64.js +2 -2
  57. package/lib/util/internalSerializables.js +11 -0
  58. package/lib/web/JsonpChunkLoadingRuntimeModule.js +3 -3
  59. package/lib/webpack.js +9 -1
  60. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +3 -2
  61. package/package.json +4 -4
  62. package/schemas/WebpackOptions.check.js +1 -1
  63. package/schemas/WebpackOptions.json +63 -1
  64. package/schemas/plugins/DllReferencePlugin.check.js +1 -1
  65. package/schemas/plugins/HashedModuleIdsPlugin.check.js +1 -1
  66. package/schemas/plugins/ProgressPlugin.check.js +1 -1
  67. package/schemas/plugins/asset/AssetParserOptions.check.js +1 -1
  68. package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
  69. package/schemas/plugins/container/ContainerPlugin.json +2 -1
  70. package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
  71. package/schemas/plugins/container/ContainerReferencePlugin.json +1 -0
  72. package/schemas/plugins/container/ExternalsType.check.js +1 -1
  73. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  74. package/schemas/plugins/container/ModuleFederationPlugin.json +3 -1
  75. package/schemas/plugins/css/CssGeneratorOptions.check.d.ts +7 -0
  76. package/schemas/plugins/css/CssGeneratorOptions.check.js +6 -0
  77. package/schemas/plugins/css/CssGeneratorOptions.json +3 -0
  78. package/schemas/plugins/css/CssParserOptions.check.d.ts +7 -0
  79. package/schemas/plugins/css/CssParserOptions.check.js +6 -0
  80. package/schemas/plugins/css/CssParserOptions.json +3 -0
  81. package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.js +1 -1
  82. package/schemas/plugins/optimize/LimitChunkCountPlugin.check.js +1 -1
  83. package/schemas/plugins/optimize/MinChunkSizePlugin.check.js +1 -1
  84. package/types.d.ts +147 -21
@@ -0,0 +1,85 @@
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Ivan Kopeykin @vankop
4
+ */
5
+
6
+ "use strict";
7
+
8
+ const makeSerializable = require("../util/makeSerializable");
9
+ const NullDependency = require("./NullDependency");
10
+
11
+ /** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
12
+ /** @typedef {import("../Dependency")} Dependency */
13
+ /** @typedef {import("../Dependency").ExportsSpec} ExportsSpec */
14
+ /** @typedef {import("../DependencyTemplate").CssDependencyTemplateContext} DependencyTemplateContext */
15
+ /** @typedef {import("../ModuleGraph")} ModuleGraph */
16
+
17
+ class CssExportDependency extends NullDependency {
18
+ /**
19
+ * @param {string} name name
20
+ * @param {string} value value
21
+ */
22
+ constructor(name, value) {
23
+ super();
24
+ this.name = name;
25
+ this.value = value;
26
+ }
27
+
28
+ get type() {
29
+ return "css :export";
30
+ }
31
+
32
+ /**
33
+ * Returns the exported names
34
+ * @param {ModuleGraph} moduleGraph module graph
35
+ * @returns {ExportsSpec | undefined} export names
36
+ */
37
+ getExports(moduleGraph) {
38
+ const name = this.name;
39
+ return {
40
+ exports: [
41
+ {
42
+ name,
43
+ canMangle: true
44
+ }
45
+ ],
46
+ dependencies: undefined
47
+ };
48
+ }
49
+
50
+ serialize(context) {
51
+ const { write } = context;
52
+ write(this.name);
53
+ write(this.value);
54
+ super.serialize(context);
55
+ }
56
+
57
+ deserialize(context) {
58
+ const { read } = context;
59
+ this.name = read();
60
+ this.value = read();
61
+ super.deserialize(context);
62
+ }
63
+ }
64
+
65
+ CssExportDependency.Template = class CssExportDependencyTemplate extends (
66
+ NullDependency.Template
67
+ ) {
68
+ /**
69
+ * @param {Dependency} dependency the dependency for which the template should be applied
70
+ * @param {ReplaceSource} source the current replace source which can be modified
71
+ * @param {DependencyTemplateContext} templateContext the context object
72
+ * @returns {void}
73
+ */
74
+ apply(dependency, source, { cssExports }) {
75
+ const dep = /** @type {CssExportDependency} */ (dependency);
76
+ cssExports.set(dep.name, dep.value);
77
+ }
78
+ };
79
+
80
+ makeSerializable(
81
+ CssExportDependency,
82
+ "webpack/lib/dependencies/CssExportDependency"
83
+ );
84
+
85
+ module.exports = CssExportDependency;
@@ -0,0 +1,75 @@
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Ivan Kopeykin @vankop
4
+ */
5
+
6
+ "use strict";
7
+
8
+ const makeSerializable = require("../util/makeSerializable");
9
+ const ModuleDependency = require("./ModuleDependency");
10
+
11
+ /** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
12
+ /** @typedef {import("../ChunkGraph")} ChunkGraph */
13
+ /** @typedef {import("../Dependency")} Dependency */
14
+ /** @typedef {import("../Dependency").UpdateHashContext} UpdateHashContext */
15
+ /** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
16
+ /** @typedef {import("../Module")} Module */
17
+ /** @typedef {import("../ModuleGraph")} ModuleGraph */
18
+ /** @typedef {import("../ModuleGraphConnection")} ModuleGraphConnection */
19
+ /** @typedef {import("../ModuleGraphConnection").ConnectionState} ConnectionState */
20
+ /** @typedef {import("../util/Hash")} Hash */
21
+ /** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
22
+
23
+ class CssImportDependency extends ModuleDependency {
24
+ /**
25
+ * @param {string} request request
26
+ * @param {[number, number]} range range of the argument
27
+ * @param {string | undefined} supports list of supports conditions
28
+ * @param {string | undefined} media list of media conditions
29
+ */
30
+ constructor(request, range, supports, media) {
31
+ super(request);
32
+ this.range = range;
33
+ this.supports = supports;
34
+ this.media = media;
35
+ }
36
+
37
+ get type() {
38
+ return "css @import";
39
+ }
40
+
41
+ get category() {
42
+ return "css-import";
43
+ }
44
+
45
+ /**
46
+ * @param {string} context context directory
47
+ * @returns {Module} a module
48
+ */
49
+ createIgnoredModule(context) {
50
+ return null;
51
+ }
52
+ }
53
+
54
+ CssImportDependency.Template = class CssImportDependencyTemplate extends (
55
+ ModuleDependency.Template
56
+ ) {
57
+ /**
58
+ * @param {Dependency} dependency the dependency for which the template should be applied
59
+ * @param {ReplaceSource} source the current replace source which can be modified
60
+ * @param {DependencyTemplateContext} templateContext the context object
61
+ * @returns {void}
62
+ */
63
+ apply(dependency, source, templateContext) {
64
+ const dep = /** @type {CssImportDependency} */ (dependency);
65
+
66
+ source.replace(dep.range[0], dep.range[1] - 1, "");
67
+ }
68
+ };
69
+
70
+ makeSerializable(
71
+ CssImportDependency,
72
+ "webpack/lib/dependencies/CssImportDependency"
73
+ );
74
+
75
+ module.exports = CssImportDependency;
@@ -0,0 +1,119 @@
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Ivan Kopeykin @vankop
4
+ */
5
+
6
+ "use strict";
7
+
8
+ const makeSerializable = require("../util/makeSerializable");
9
+ const NullDependency = require("./NullDependency");
10
+
11
+ /** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
12
+ /** @typedef {import("../Dependency")} Dependency */
13
+ /** @typedef {import("../Dependency").ExportsSpec} ExportsSpec */
14
+ /** @typedef {import("../DependencyTemplate").CssDependencyTemplateContext} DependencyTemplateContext */
15
+ /** @typedef {import("../ModuleGraph")} ModuleGraph */
16
+
17
+ class CssLocalIdentifierDependency extends NullDependency {
18
+ /**
19
+ * @param {string} name name
20
+ * @param {[number, number]} range range
21
+ * @param {string=} prefix prefix
22
+ */
23
+ constructor(name, range, prefix = "") {
24
+ super();
25
+ this.name = name;
26
+ this.range = range;
27
+ this.prefix = prefix;
28
+ }
29
+
30
+ get type() {
31
+ return "css local identifier";
32
+ }
33
+
34
+ /**
35
+ * Returns the exported names
36
+ * @param {ModuleGraph} moduleGraph module graph
37
+ * @returns {ExportsSpec | undefined} export names
38
+ */
39
+ getExports(moduleGraph) {
40
+ const name = this.name;
41
+ return {
42
+ exports: [
43
+ {
44
+ name,
45
+ canMangle: true
46
+ }
47
+ ],
48
+ dependencies: undefined
49
+ };
50
+ }
51
+
52
+ serialize(context) {
53
+ const { write } = context;
54
+ write(this.name);
55
+ write(this.range);
56
+ write(this.prefix);
57
+ super.serialize(context);
58
+ }
59
+
60
+ deserialize(context) {
61
+ const { read } = context;
62
+ this.name = read();
63
+ this.range = read();
64
+ this.prefix = read();
65
+ super.deserialize(context);
66
+ }
67
+ }
68
+
69
+ const escapeCssIdentifier = (str, omitUnderscore) => {
70
+ const escaped = `${str}`.replace(
71
+ // cspell:word uffff
72
+ /[^a-zA-Z0-9_\u0081-\uffff-]/g,
73
+ s => `\\${s}`
74
+ );
75
+ return !omitUnderscore && /^(?!--)[0-9-]/.test(escaped)
76
+ ? `_${escaped}`
77
+ : escaped;
78
+ };
79
+
80
+ CssLocalIdentifierDependency.Template = class CssLocalIdentifierDependencyTemplate extends (
81
+ NullDependency.Template
82
+ ) {
83
+ /**
84
+ * @param {Dependency} dependency the dependency for which the template should be applied
85
+ * @param {ReplaceSource} source the current replace source which can be modified
86
+ * @param {DependencyTemplateContext} templateContext the context object
87
+ * @returns {void}
88
+ */
89
+ apply(
90
+ dependency,
91
+ source,
92
+ { module, moduleGraph, chunkGraph, runtime, runtimeTemplate, cssExports }
93
+ ) {
94
+ const dep = /** @type {CssLocalIdentifierDependency} */ (dependency);
95
+ const used = moduleGraph
96
+ .getExportInfo(module, dep.name)
97
+ .getUsedName(dep.name, runtime);
98
+ const moduleId = chunkGraph.getModuleId(module);
99
+ const identifier =
100
+ dep.prefix +
101
+ (runtimeTemplate.outputOptions.uniqueName
102
+ ? runtimeTemplate.outputOptions.uniqueName + "-"
103
+ : "") +
104
+ (used ? moduleId + "-" + used : "-");
105
+ source.replace(
106
+ dep.range[0],
107
+ dep.range[1] - 1,
108
+ escapeCssIdentifier(identifier, dep.prefix)
109
+ );
110
+ if (used) cssExports.set(used, identifier);
111
+ }
112
+ };
113
+
114
+ makeSerializable(
115
+ CssLocalIdentifierDependency,
116
+ "webpack/lib/dependencies/CssLocalIdentifierDependency"
117
+ );
118
+
119
+ module.exports = CssLocalIdentifierDependency;
@@ -0,0 +1,101 @@
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Ivan Kopeykin @vankop
4
+ */
5
+
6
+ "use strict";
7
+
8
+ const Dependency = require("../Dependency");
9
+ const makeSerializable = require("../util/makeSerializable");
10
+ const CssLocalIdentifierDependency = require("./CssLocalIdentifierDependency");
11
+
12
+ /** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
13
+ /** @typedef {import("../Dependency").ExportsSpec} ExportsSpec */
14
+ /** @typedef {import("../Dependency").ReferencedExport} ReferencedExport */
15
+ /** @typedef {import("../DependencyTemplate").CssDependencyTemplateContext} DependencyTemplateContext */
16
+ /** @typedef {import("../ModuleGraph")} ModuleGraph */
17
+ /** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
18
+
19
+ class CssSelfLocalIdentifierDependency extends CssLocalIdentifierDependency {
20
+ /**
21
+ * @param {string} name name
22
+ * @param {[number, number]} range range
23
+ * @param {string=} prefix prefix
24
+ * @param {Set<string>=} declaredSet set of declared names (will only be active when in declared set)
25
+ */
26
+ constructor(name, range, prefix = "", declaredSet = undefined) {
27
+ super(name, range, prefix);
28
+ this.declaredSet = declaredSet;
29
+ }
30
+
31
+ get type() {
32
+ return "css self local identifier";
33
+ }
34
+
35
+ get category() {
36
+ return "self";
37
+ }
38
+
39
+ /**
40
+ * @returns {string | null} an identifier to merge equal requests
41
+ */
42
+ getResourceIdentifier() {
43
+ return `self`;
44
+ }
45
+ /**
46
+ * Returns the exported names
47
+ * @param {ModuleGraph} moduleGraph module graph
48
+ * @returns {ExportsSpec | undefined} export names
49
+ */
50
+ getExports(moduleGraph) {
51
+ if (this.declaredSet && !this.declaredSet.has(this.name)) return;
52
+ return super.getExports(moduleGraph);
53
+ }
54
+
55
+ /**
56
+ * Returns list of exports referenced by this dependency
57
+ * @param {ModuleGraph} moduleGraph module graph
58
+ * @param {RuntimeSpec} runtime the runtime for which the module is analysed
59
+ * @returns {(string[] | ReferencedExport)[]} referenced exports
60
+ */
61
+ getReferencedExports(moduleGraph, runtime) {
62
+ if (this.declaredSet && !this.declaredSet.has(this.name))
63
+ return Dependency.NO_EXPORTS_REFERENCED;
64
+ return [[this.name]];
65
+ }
66
+
67
+ serialize(context) {
68
+ const { write } = context;
69
+ write(this.declaredSet);
70
+ super.serialize(context);
71
+ }
72
+
73
+ deserialize(context) {
74
+ const { read } = context;
75
+ this.declaredSet = read();
76
+ super.deserialize(context);
77
+ }
78
+ }
79
+
80
+ CssSelfLocalIdentifierDependency.Template = class CssSelfLocalIdentifierDependencyTemplate extends (
81
+ CssLocalIdentifierDependency.Template
82
+ ) {
83
+ /**
84
+ * @param {Dependency} dependency the dependency for which the template should be applied
85
+ * @param {ReplaceSource} source the current replace source which can be modified
86
+ * @param {DependencyTemplateContext} templateContext the context object
87
+ * @returns {void}
88
+ */
89
+ apply(dependency, source, templateContext) {
90
+ const dep = /** @type {CssSelfLocalIdentifierDependency} */ (dependency);
91
+ if (dep.declaredSet && !dep.declaredSet.has(dep.name)) return;
92
+ super.apply(dependency, source, templateContext);
93
+ }
94
+ };
95
+
96
+ makeSerializable(
97
+ CssSelfLocalIdentifierDependency,
98
+ "webpack/lib/dependencies/CssSelfLocalIdentifierDependency"
99
+ );
100
+
101
+ module.exports = CssSelfLocalIdentifierDependency;
@@ -0,0 +1,132 @@
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Ivan Kopeykin @vankop
4
+ */
5
+
6
+ "use strict";
7
+
8
+ const makeSerializable = require("../util/makeSerializable");
9
+ const memoize = require("../util/memoize");
10
+ const ModuleDependency = require("./ModuleDependency");
11
+
12
+ /** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
13
+ /** @typedef {import("../ChunkGraph")} ChunkGraph */
14
+ /** @typedef {import("../Dependency")} Dependency */
15
+ /** @typedef {import("../Dependency").UpdateHashContext} UpdateHashContext */
16
+ /** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
17
+ /** @typedef {import("../Module")} Module */
18
+ /** @typedef {import("../ModuleGraph")} ModuleGraph */
19
+ /** @typedef {import("../ModuleGraphConnection")} ModuleGraphConnection */
20
+ /** @typedef {import("../ModuleGraphConnection").ConnectionState} ConnectionState */
21
+ /** @typedef {import("../util/Hash")} Hash */
22
+ /** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
23
+
24
+ const getRawDataUrlModule = memoize(() => require("../asset/RawDataUrlModule"));
25
+
26
+ class CssUrlDependency extends ModuleDependency {
27
+ /**
28
+ * @param {string} request request
29
+ * @param {[number, number]} range range of the argument
30
+ * @param {string} cssFunctionKind kind of css function, e. g. url(), image()
31
+ */
32
+ constructor(request, range, cssFunctionKind) {
33
+ super(request);
34
+ this.range = range;
35
+ this.cssFunctionKind = cssFunctionKind;
36
+ }
37
+
38
+ get type() {
39
+ return "css url()";
40
+ }
41
+
42
+ get category() {
43
+ return "url";
44
+ }
45
+
46
+ /**
47
+ * @param {string} context context directory
48
+ * @returns {Module} a module
49
+ */
50
+ createIgnoredModule(context) {
51
+ const RawDataUrlModule = getRawDataUrlModule();
52
+ return new RawDataUrlModule("data:,", `ignored-asset`, `(ignored asset)`);
53
+ }
54
+
55
+ serialize(context) {
56
+ const { write } = context;
57
+ write(this.cssFunctionKind);
58
+ super.serialize(context);
59
+ }
60
+
61
+ deserialize(context) {
62
+ const { read } = context;
63
+ this.cssFunctionKind = read();
64
+ super.deserialize(context);
65
+ }
66
+ }
67
+
68
+ const cssEscapeString = str => {
69
+ let countWhiteOrBracket = 0;
70
+ let countQuotation = 0;
71
+ let countApostrophe = 0;
72
+ for (let i = 0; i < str.length; i++) {
73
+ const cc = str.charCodeAt(i);
74
+ switch (cc) {
75
+ case 9: // tab
76
+ case 10: // nl
77
+ case 32: // space
78
+ case 40: // (
79
+ case 41: // )
80
+ countWhiteOrBracket++;
81
+ break;
82
+ case 34:
83
+ countQuotation++;
84
+ break;
85
+ case 39:
86
+ countApostrophe++;
87
+ break;
88
+ }
89
+ }
90
+ if (countWhiteOrBracket < 2) {
91
+ return str.replace(/[\n\t ()'"\\]/g, m => `\\${m}`);
92
+ } else if (countQuotation <= countApostrophe) {
93
+ return `"${str.replace(/[\n"\\]/g, m => `\\${m}`)}"`;
94
+ } else {
95
+ return `'${str.replace(/[\n'\\]/g, m => `\\${m}`)}'`;
96
+ }
97
+ };
98
+
99
+ CssUrlDependency.Template = class CssUrlDependencyTemplate extends (
100
+ ModuleDependency.Template
101
+ ) {
102
+ /**
103
+ * @param {Dependency} dependency the dependency for which the template should be applied
104
+ * @param {ReplaceSource} source the current replace source which can be modified
105
+ * @param {DependencyTemplateContext} templateContext the context object
106
+ * @returns {void}
107
+ */
108
+ apply(
109
+ dependency,
110
+ source,
111
+ { runtime, moduleGraph, runtimeTemplate, codeGenerationResults }
112
+ ) {
113
+ const dep = /** @type {CssUrlDependency} */ (dependency);
114
+
115
+ source.replace(
116
+ dep.range[0],
117
+ dep.range[1] - 1,
118
+ `${dep.cssFunctionKind}(${cssEscapeString(
119
+ runtimeTemplate.assetUrl({
120
+ publicPath: "",
121
+ runtime,
122
+ module: moduleGraph.getModule(dep),
123
+ codeGenerationResults
124
+ })
125
+ )})`
126
+ );
127
+ }
128
+ };
129
+
130
+ makeSerializable(CssUrlDependency, "webpack/lib/dependencies/CssUrlDependency");
131
+
132
+ module.exports = CssUrlDependency;
@@ -25,7 +25,7 @@ const ModuleDependency = require("./ModuleDependency");
25
25
  /** @typedef {import("../util/Hash")} Hash */
26
26
  /** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
27
27
 
28
- const getRawModule = memoize(() => require("../RawModule"));
28
+ const getRawDataUrlModule = memoize(() => require("../asset/RawDataUrlModule"));
29
29
 
30
30
  class URLDependency extends ModuleDependency {
31
31
  /**
@@ -68,13 +68,8 @@ class URLDependency extends ModuleDependency {
68
68
  * @returns {Module} a module
69
69
  */
70
70
  createIgnoredModule(context) {
71
- const RawModule = getRawModule();
72
- return new RawModule(
73
- 'module.exports = "data:,";',
74
- `ignored-asset`,
75
- `(ignored asset)`,
76
- new Set([RuntimeGlobals.module])
77
- );
71
+ const RawDataUrlModule = getRawDataUrlModule();
72
+ return new RawDataUrlModule("data:,", `ignored-asset`, `(ignored asset)`);
78
73
  }
79
74
 
80
75
  serialize(context) {
@@ -5,18 +5,16 @@
5
5
 
6
6
  "use strict";
7
7
 
8
- const { ConcatSource, RawSource } = require("webpack-sources");
8
+ const { ConcatSource } = require("webpack-sources");
9
9
  const { RuntimeGlobals } = require("..");
10
10
  const HotUpdateChunk = require("../HotUpdateChunk");
11
11
  const Template = require("../Template");
12
+ const { getAllChunks } = require("../javascript/ChunkHelpers");
12
13
  const {
13
14
  getCompilationHooks,
14
15
  getChunkFilenameTemplate
15
16
  } = require("../javascript/JavascriptModulesPlugin");
16
- const {
17
- generateEntryStartup,
18
- updateHashForEntryStartup
19
- } = require("../javascript/StartupHelpers");
17
+ const { updateHashForEntryStartup } = require("../javascript/StartupHelpers");
20
18
 
21
19
  /** @typedef {import("../Compiler")} Compiler */
22
20
 
@@ -84,63 +82,90 @@ class ModuleChunkFormatPlugin {
84
82
  }
85
83
  )
86
84
  .split("/");
87
- const runtimeOutputName = compilation
88
- .getPath(
89
- getChunkFilenameTemplate(
90
- runtimeChunk,
91
- compilation.outputOptions
92
- ),
93
- {
94
- chunk: runtimeChunk,
95
- contentHashType: "javascript"
96
- }
97
- )
98
- .split("/");
99
85
 
100
86
  // remove filename, we only need the directory
101
- const outputFilename = currentOutputName.pop();
87
+ currentOutputName.pop();
102
88
 
103
- // remove common parts
104
- while (
105
- currentOutputName.length > 0 &&
106
- runtimeOutputName.length > 0 &&
107
- currentOutputName[0] === runtimeOutputName[0]
108
- ) {
109
- currentOutputName.shift();
110
- runtimeOutputName.shift();
111
- }
89
+ const getRelativePath = chunk => {
90
+ const baseOutputName = currentOutputName.slice();
91
+ const chunkOutputName = compilation
92
+ .getPath(
93
+ getChunkFilenameTemplate(
94
+ chunk,
95
+ compilation.outputOptions
96
+ ),
97
+ {
98
+ chunk: chunk,
99
+ contentHashType: "javascript"
100
+ }
101
+ )
102
+ .split("/");
112
103
 
113
- // create final path
114
- const runtimePath =
115
- (currentOutputName.length > 0
116
- ? "../".repeat(currentOutputName.length)
117
- : "./") + runtimeOutputName.join("/");
104
+ // remove common parts
105
+ while (
106
+ baseOutputName.length > 0 &&
107
+ chunkOutputName.length > 0 &&
108
+ baseOutputName[0] === chunkOutputName[0]
109
+ ) {
110
+ baseOutputName.shift();
111
+ chunkOutputName.shift();
112
+ }
113
+ // create final path
114
+ return (
115
+ (baseOutputName.length > 0
116
+ ? "../".repeat(baseOutputName.length)
117
+ : "./") + chunkOutputName.join("/")
118
+ );
119
+ };
118
120
 
119
121
  const entrySource = new ConcatSource();
120
122
  entrySource.add(source);
121
123
  entrySource.add(";\n\n// load runtime\n");
122
124
  entrySource.add(
123
125
  `import __webpack_require__ from ${JSON.stringify(
124
- runtimePath
125
- )};\n`
126
- );
127
- entrySource.add(
128
- `import * as __webpack_self_exports__ from ${JSON.stringify(
129
- "./" + outputFilename
126
+ getRelativePath(runtimeChunk)
130
127
  )};\n`
131
128
  );
132
- entrySource.add(
133
- `${RuntimeGlobals.externalInstallChunk}(__webpack_self_exports__);\n`
134
- );
135
- const startupSource = new RawSource(
136
- generateEntryStartup(
137
- chunkGraph,
138
- runtimeTemplate,
139
- entries,
140
- chunk,
141
- false
142
- )
129
+
130
+ const startupSource = new ConcatSource();
131
+ startupSource.add(
132
+ `var __webpack_exec__ = ${runtimeTemplate.returningFunction(
133
+ `__webpack_require__(${RuntimeGlobals.entryModuleId} = moduleId)`,
134
+ "moduleId"
135
+ )}\n`
143
136
  );
137
+
138
+ const loadedChunks = new Set();
139
+ let index = 0;
140
+ for (let i = 0; i < entries.length; i++) {
141
+ const [module, entrypoint] = entries[i];
142
+ const final = i + 1 === entries.length;
143
+ const moduleId = chunkGraph.getModuleId(module);
144
+ const chunks = getAllChunks(
145
+ entrypoint,
146
+ runtimeChunk,
147
+ undefined
148
+ );
149
+ for (const chunk of chunks) {
150
+ if (loadedChunks.has(chunk)) continue;
151
+ loadedChunks.add(chunk);
152
+ startupSource.add(
153
+ `import * as __webpack_chunk_${index}__ from ${JSON.stringify(
154
+ getRelativePath(chunk)
155
+ )};\n`
156
+ );
157
+ startupSource.add(
158
+ `${RuntimeGlobals.externalInstallChunk}(__webpack_chunk_${index}__);\n`
159
+ );
160
+ index++;
161
+ }
162
+ startupSource.add(
163
+ `${
164
+ final ? "var __webpack_exports__ = " : ""
165
+ }__webpack_exec__(${JSON.stringify(moduleId)});\n`
166
+ );
167
+ }
168
+
144
169
  entrySource.add(
145
170
  hooks.renderStartup.call(
146
171
  startupSource,