webpack 5.64.3 → 5.67.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.
- package/README.md +1 -1
- package/lib/Cache.js +1 -1
- package/lib/CacheFacade.js +4 -11
- package/lib/Chunk.js +2 -0
- package/lib/CleanPlugin.js +1 -1
- package/lib/Compilation.js +91 -47
- package/lib/Compiler.js +57 -3
- package/lib/ContextModule.js +21 -17
- package/lib/DelegatedModule.js +1 -1
- package/lib/Dependency.js +10 -0
- package/lib/DependencyTemplate.js +9 -0
- package/lib/DependencyTemplates.js +1 -1
- package/lib/DllModule.js +1 -1
- package/lib/EvalDevToolModulePlugin.js +16 -1
- package/lib/EvalSourceMapDevToolPlugin.js +18 -1
- package/lib/ExternalModule.js +94 -54
- package/lib/ExternalModuleFactoryPlugin.js +1 -1
- package/lib/FileSystemInfo.js +29 -25
- package/lib/Generator.js +2 -0
- package/lib/HookWebpackError.js +1 -1
- package/lib/Module.js +25 -2
- package/lib/ModuleFilenameHelpers.js +5 -1
- package/lib/MultiCompiler.js +1 -1
- package/lib/MultiWatching.js +1 -1
- package/lib/NormalModule.js +9 -5
- package/lib/RawModule.js +1 -1
- package/lib/RuntimeGlobals.js +29 -1
- package/lib/RuntimeModule.js +1 -1
- package/lib/RuntimePlugin.js +50 -0
- package/lib/RuntimeTemplate.js +113 -2
- package/lib/Template.js +2 -1
- package/lib/WatchIgnorePlugin.js +14 -1
- package/lib/Watching.js +33 -19
- package/lib/WebpackOptionsApply.js +43 -2
- package/lib/asset/AssetGenerator.js +71 -30
- package/lib/asset/AssetModulesPlugin.js +3 -0
- package/lib/asset/RawDataUrlModule.js +148 -0
- package/lib/cache/ResolverCachePlugin.js +1 -1
- package/lib/cli.js +44 -3
- package/lib/config/browserslistTargetHandler.js +38 -1
- package/lib/config/defaults.js +79 -6
- package/lib/config/normalization.js +5 -0
- package/lib/config/target.js +10 -0
- package/lib/container/ContainerEntryModule.js +8 -5
- package/lib/container/FallbackModule.js +4 -4
- package/lib/container/RemoteModule.js +4 -2
- package/lib/css/CssExportsGenerator.js +139 -0
- package/lib/css/CssGenerator.js +109 -0
- package/lib/css/CssLoadingRuntimeModule.js +447 -0
- package/lib/css/CssModulesPlugin.js +461 -0
- package/lib/css/CssParser.js +618 -0
- package/lib/css/walkCssTokens.js +659 -0
- package/lib/debug/ProfilingPlugin.js +12 -10
- package/lib/dependencies/CreateScriptUrlDependency.js +12 -0
- package/lib/dependencies/CssExportDependency.js +85 -0
- package/lib/dependencies/CssImportDependency.js +75 -0
- package/lib/dependencies/CssLocalIdentifierDependency.js +119 -0
- package/lib/dependencies/CssSelfLocalIdentifierDependency.js +101 -0
- package/lib/dependencies/CssUrlDependency.js +132 -0
- package/lib/dependencies/LoaderPlugin.js +2 -2
- package/lib/dependencies/URLDependency.js +3 -8
- package/lib/esm/ModuleChunkFormatPlugin.js +74 -49
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +1 -1
- package/lib/hmr/LazyCompilationPlugin.js +45 -21
- package/lib/hmr/lazyCompilationBackend.js +4 -2
- package/lib/ids/DeterministicModuleIdsPlugin.js +55 -35
- package/lib/ids/HashedModuleIdsPlugin.js +9 -12
- package/lib/ids/IdHelpers.js +24 -10
- package/lib/ids/NamedModuleIdsPlugin.js +6 -9
- package/lib/ids/NaturalModuleIdsPlugin.js +10 -13
- package/lib/ids/OccurrenceModuleIdsPlugin.js +13 -10
- package/lib/ids/SyncModuleIdsPlugin.js +140 -0
- package/lib/index.js +8 -0
- package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +2 -2
- package/lib/javascript/ChunkHelpers.js +33 -0
- package/lib/javascript/JavascriptGenerator.js +1 -0
- package/lib/javascript/JavascriptParser.js +16 -8
- package/lib/javascript/StartupHelpers.js +4 -28
- package/lib/library/AssignLibraryPlugin.js +31 -13
- package/lib/library/EnableLibraryPlugin.js +11 -0
- package/lib/node/NodeWatchFileSystem.js +85 -31
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +1 -1
- package/lib/node/RequireChunkLoadingRuntimeModule.js +1 -1
- package/lib/optimize/ConcatenatedModule.js +11 -5
- package/lib/runtime/CreateScriptRuntimeModule.js +36 -0
- package/lib/runtime/CreateScriptUrlRuntimeModule.js +9 -34
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +76 -0
- package/lib/schemes/HttpUriPlugin.js +8 -8
- package/lib/sharing/ConsumeSharedModule.js +8 -2
- package/lib/sharing/ConsumeSharedRuntimeModule.js +25 -4
- package/lib/sharing/ProvideSharedModule.js +4 -2
- package/lib/sharing/utils.js +1 -1
- package/lib/stats/DefaultStatsFactoryPlugin.js +112 -67
- package/lib/stats/DefaultStatsPrinterPlugin.js +89 -24
- package/lib/util/AsyncQueue.js +1 -1
- package/lib/util/extractUrlAndGlobal.js +3 -0
- package/lib/util/fs.js +10 -0
- package/lib/util/hash/xxhash64.js +2 -2
- package/lib/util/internalSerializables.js +11 -0
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +3 -3
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +3 -11
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +3 -2
- package/package.json +5 -12
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +100 -1
- package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -1
- package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +1 -1
- package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
- package/schemas/plugins/container/ContainerPlugin.json +2 -1
- package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
- package/schemas/plugins/container/ContainerReferencePlugin.json +1 -0
- package/schemas/plugins/container/ExternalsType.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.json +3 -1
- package/schemas/plugins/css/CssGeneratorOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssGeneratorOptions.check.js +6 -0
- package/schemas/plugins/css/CssGeneratorOptions.json +3 -0
- package/schemas/plugins/css/CssParserOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssParserOptions.check.js +6 -0
- package/schemas/plugins/css/CssParserOptions.json +3 -0
- package/types.d.ts +305 -58
@@ -0,0 +1,139 @@
|
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Sergey Melyukov @smelukov
|
4
|
+
*/
|
5
|
+
|
6
|
+
"use strict";
|
7
|
+
|
8
|
+
const { ReplaceSource, RawSource, ConcatSource } = require("webpack-sources");
|
9
|
+
const { UsageState } = require("../ExportsInfo");
|
10
|
+
const Generator = require("../Generator");
|
11
|
+
const RuntimeGlobals = require("../RuntimeGlobals");
|
12
|
+
const Template = require("../Template");
|
13
|
+
|
14
|
+
/** @typedef {import("webpack-sources").Source} Source */
|
15
|
+
/** @typedef {import("../Dependency")} Dependency */
|
16
|
+
/** @typedef {import("../Generator").GenerateContext} GenerateContext */
|
17
|
+
/** @typedef {import("../Generator").UpdateHashContext} UpdateHashContext */
|
18
|
+
/** @typedef {import("../Module").ConcatenationBailoutReasonContext} ConcatenationBailoutReasonContext */
|
19
|
+
/** @typedef {import("../NormalModule")} NormalModule */
|
20
|
+
/** @typedef {import("../util/Hash")} Hash */
|
21
|
+
|
22
|
+
const TYPES = new Set(["javascript"]);
|
23
|
+
|
24
|
+
class CssExportsGenerator extends Generator {
|
25
|
+
constructor() {
|
26
|
+
super();
|
27
|
+
}
|
28
|
+
|
29
|
+
// TODO add getConcatenationBailoutReason to allow concatenation
|
30
|
+
// but how to make it have a module id
|
31
|
+
|
32
|
+
/**
|
33
|
+
* @param {NormalModule} module module for which the code should be generated
|
34
|
+
* @param {GenerateContext} generateContext context for generate
|
35
|
+
* @returns {Source} generated code
|
36
|
+
*/
|
37
|
+
generate(module, generateContext) {
|
38
|
+
const source = new ReplaceSource(new RawSource(""));
|
39
|
+
const initFragments = [];
|
40
|
+
const cssExports = new Map();
|
41
|
+
|
42
|
+
generateContext.runtimeRequirements.add(RuntimeGlobals.module);
|
43
|
+
|
44
|
+
const runtimeRequirements = new Set();
|
45
|
+
|
46
|
+
const templateContext = {
|
47
|
+
runtimeTemplate: generateContext.runtimeTemplate,
|
48
|
+
dependencyTemplates: generateContext.dependencyTemplates,
|
49
|
+
moduleGraph: generateContext.moduleGraph,
|
50
|
+
chunkGraph: generateContext.chunkGraph,
|
51
|
+
module,
|
52
|
+
runtime: generateContext.runtime,
|
53
|
+
runtimeRequirements: runtimeRequirements,
|
54
|
+
concatenationScope: generateContext.concatenationScope,
|
55
|
+
codeGenerationResults: generateContext.codeGenerationResults,
|
56
|
+
initFragments,
|
57
|
+
cssExports
|
58
|
+
};
|
59
|
+
|
60
|
+
const handleDependency = dependency => {
|
61
|
+
const constructor = /** @type {new (...args: any[]) => Dependency} */ (
|
62
|
+
dependency.constructor
|
63
|
+
);
|
64
|
+
const template = generateContext.dependencyTemplates.get(constructor);
|
65
|
+
if (!template) {
|
66
|
+
throw new Error(
|
67
|
+
"No template for dependency: " + dependency.constructor.name
|
68
|
+
);
|
69
|
+
}
|
70
|
+
|
71
|
+
template.apply(dependency, source, templateContext);
|
72
|
+
};
|
73
|
+
module.dependencies.forEach(handleDependency);
|
74
|
+
|
75
|
+
if (generateContext.concatenationScope) {
|
76
|
+
const source = new ConcatSource();
|
77
|
+
const usedIdentifiers = new Set();
|
78
|
+
for (const [k, v] of cssExports) {
|
79
|
+
let identifier = Template.toIdentifier(k);
|
80
|
+
let i = 0;
|
81
|
+
while (usedIdentifiers.has(identifier)) {
|
82
|
+
identifier = Template.toIdentifier(k + i);
|
83
|
+
}
|
84
|
+
usedIdentifiers.add(identifier);
|
85
|
+
generateContext.concatenationScope.registerExport(k, identifier);
|
86
|
+
source.add(
|
87
|
+
`${
|
88
|
+
generateContext.runtimeTemplate.supportsConst ? "const" : "var"
|
89
|
+
} ${identifier} = ${JSON.stringify(v)};\n`
|
90
|
+
);
|
91
|
+
}
|
92
|
+
return source;
|
93
|
+
} else {
|
94
|
+
const otherUsed =
|
95
|
+
generateContext.moduleGraph
|
96
|
+
.getExportsInfo(module)
|
97
|
+
.otherExportsInfo.getUsed(generateContext.runtime) !==
|
98
|
+
UsageState.Unused;
|
99
|
+
if (otherUsed) {
|
100
|
+
generateContext.runtimeRequirements.add(
|
101
|
+
RuntimeGlobals.makeNamespaceObject
|
102
|
+
);
|
103
|
+
}
|
104
|
+
return new RawSource(
|
105
|
+
`${otherUsed ? `${RuntimeGlobals.makeNamespaceObject}(` : ""}${
|
106
|
+
module.moduleArgument
|
107
|
+
}.exports = {\n${Array.from(
|
108
|
+
cssExports,
|
109
|
+
([k, v]) => `\t${JSON.stringify(k)}: ${JSON.stringify(v)}`
|
110
|
+
).join(",\n")}\n}${otherUsed ? ")" : ""};`
|
111
|
+
);
|
112
|
+
}
|
113
|
+
}
|
114
|
+
|
115
|
+
/**
|
116
|
+
* @param {NormalModule} module fresh module
|
117
|
+
* @returns {Set<string>} available types (do not mutate)
|
118
|
+
*/
|
119
|
+
getTypes(module) {
|
120
|
+
return TYPES;
|
121
|
+
}
|
122
|
+
|
123
|
+
/**
|
124
|
+
* @param {NormalModule} module the module
|
125
|
+
* @param {string=} type source type
|
126
|
+
* @returns {number} estimate size of the module
|
127
|
+
*/
|
128
|
+
getSize(module, type) {
|
129
|
+
return 42;
|
130
|
+
}
|
131
|
+
|
132
|
+
/**
|
133
|
+
* @param {Hash} hash hash that will be modified
|
134
|
+
* @param {UpdateHashContext} updateHashContext context for updating hash
|
135
|
+
*/
|
136
|
+
updateHash(hash, { module }) {}
|
137
|
+
}
|
138
|
+
|
139
|
+
module.exports = CssExportsGenerator;
|
@@ -0,0 +1,109 @@
|
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Sergey Melyukov @smelukov
|
4
|
+
*/
|
5
|
+
|
6
|
+
"use strict";
|
7
|
+
|
8
|
+
const { ReplaceSource } = require("webpack-sources");
|
9
|
+
const Generator = require("../Generator");
|
10
|
+
const InitFragment = require("../InitFragment");
|
11
|
+
const RuntimeGlobals = require("../RuntimeGlobals");
|
12
|
+
|
13
|
+
/** @typedef {import("webpack-sources").Source} Source */
|
14
|
+
/** @typedef {import("../Dependency")} Dependency */
|
15
|
+
/** @typedef {import("../Generator").GenerateContext} GenerateContext */
|
16
|
+
/** @typedef {import("../Generator").UpdateHashContext} UpdateHashContext */
|
17
|
+
/** @typedef {import("../NormalModule")} NormalModule */
|
18
|
+
/** @typedef {import("../util/Hash")} Hash */
|
19
|
+
|
20
|
+
const TYPES = new Set(["css"]);
|
21
|
+
|
22
|
+
class CssGenerator extends Generator {
|
23
|
+
constructor() {
|
24
|
+
super();
|
25
|
+
}
|
26
|
+
|
27
|
+
/**
|
28
|
+
* @param {NormalModule} module module for which the code should be generated
|
29
|
+
* @param {GenerateContext} generateContext context for generate
|
30
|
+
* @returns {Source} generated code
|
31
|
+
*/
|
32
|
+
generate(module, generateContext) {
|
33
|
+
const originalSource = module.originalSource();
|
34
|
+
const source = new ReplaceSource(originalSource);
|
35
|
+
const initFragments = [];
|
36
|
+
const cssExports = new Map();
|
37
|
+
|
38
|
+
generateContext.runtimeRequirements.add(RuntimeGlobals.hasCssModules);
|
39
|
+
|
40
|
+
const templateContext = {
|
41
|
+
runtimeTemplate: generateContext.runtimeTemplate,
|
42
|
+
dependencyTemplates: generateContext.dependencyTemplates,
|
43
|
+
moduleGraph: generateContext.moduleGraph,
|
44
|
+
chunkGraph: generateContext.chunkGraph,
|
45
|
+
module,
|
46
|
+
runtime: generateContext.runtime,
|
47
|
+
runtimeRequirements: generateContext.runtimeRequirements,
|
48
|
+
concatenationScope: generateContext.concatenationScope,
|
49
|
+
codeGenerationResults: generateContext.codeGenerationResults,
|
50
|
+
initFragments,
|
51
|
+
cssExports
|
52
|
+
};
|
53
|
+
|
54
|
+
const handleDependency = dependency => {
|
55
|
+
const constructor = /** @type {new (...args: any[]) => Dependency} */ (
|
56
|
+
dependency.constructor
|
57
|
+
);
|
58
|
+
const template = generateContext.dependencyTemplates.get(constructor);
|
59
|
+
if (!template) {
|
60
|
+
throw new Error(
|
61
|
+
"No template for dependency: " + dependency.constructor.name
|
62
|
+
);
|
63
|
+
}
|
64
|
+
|
65
|
+
template.apply(dependency, source, templateContext);
|
66
|
+
};
|
67
|
+
module.dependencies.forEach(handleDependency);
|
68
|
+
if (module.presentationalDependencies !== undefined)
|
69
|
+
module.presentationalDependencies.forEach(handleDependency);
|
70
|
+
|
71
|
+
if (cssExports.size > 0) {
|
72
|
+
const data = generateContext.getData();
|
73
|
+
data.set("css-exports", cssExports);
|
74
|
+
}
|
75
|
+
|
76
|
+
return InitFragment.addToSource(source, initFragments, generateContext);
|
77
|
+
}
|
78
|
+
|
79
|
+
/**
|
80
|
+
* @param {NormalModule} module fresh module
|
81
|
+
* @returns {Set<string>} available types (do not mutate)
|
82
|
+
*/
|
83
|
+
getTypes(module) {
|
84
|
+
return TYPES;
|
85
|
+
}
|
86
|
+
|
87
|
+
/**
|
88
|
+
* @param {NormalModule} module the module
|
89
|
+
* @param {string=} type source type
|
90
|
+
* @returns {number} estimate size of the module
|
91
|
+
*/
|
92
|
+
getSize(module, type) {
|
93
|
+
const originalSource = module.originalSource();
|
94
|
+
|
95
|
+
if (!originalSource) {
|
96
|
+
return 0;
|
97
|
+
}
|
98
|
+
|
99
|
+
return originalSource.size();
|
100
|
+
}
|
101
|
+
|
102
|
+
/**
|
103
|
+
* @param {Hash} hash hash that will be modified
|
104
|
+
* @param {UpdateHashContext} updateHashContext context for updating hash
|
105
|
+
*/
|
106
|
+
updateHash(hash, { module }) {}
|
107
|
+
}
|
108
|
+
|
109
|
+
module.exports = CssGenerator;
|
@@ -0,0 +1,447 @@
|
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Tobias Koppers @sokra
|
4
|
+
*/
|
5
|
+
|
6
|
+
"use strict";
|
7
|
+
|
8
|
+
const { SyncWaterfallHook } = require("tapable");
|
9
|
+
const Compilation = require("../Compilation");
|
10
|
+
const RuntimeGlobals = require("../RuntimeGlobals");
|
11
|
+
const RuntimeModule = require("../RuntimeModule");
|
12
|
+
const Template = require("../Template");
|
13
|
+
const compileBooleanMatcher = require("../util/compileBooleanMatcher");
|
14
|
+
const { chunkHasCss } = require("./CssModulesPlugin");
|
15
|
+
|
16
|
+
/** @typedef {import("../Chunk")} Chunk */
|
17
|
+
|
18
|
+
/**
|
19
|
+
* @typedef {Object} JsonpCompilationPluginHooks
|
20
|
+
* @property {SyncWaterfallHook<[string, Chunk]>} createStylesheet
|
21
|
+
*/
|
22
|
+
|
23
|
+
/** @type {WeakMap<Compilation, JsonpCompilationPluginHooks>} */
|
24
|
+
const compilationHooksMap = new WeakMap();
|
25
|
+
|
26
|
+
class CssLoadingRuntimeModule extends RuntimeModule {
|
27
|
+
/**
|
28
|
+
* @param {Compilation} compilation the compilation
|
29
|
+
* @returns {JsonpCompilationPluginHooks} hooks
|
30
|
+
*/
|
31
|
+
static getCompilationHooks(compilation) {
|
32
|
+
if (!(compilation instanceof Compilation)) {
|
33
|
+
throw new TypeError(
|
34
|
+
"The 'compilation' argument must be an instance of Compilation"
|
35
|
+
);
|
36
|
+
}
|
37
|
+
let hooks = compilationHooksMap.get(compilation);
|
38
|
+
if (hooks === undefined) {
|
39
|
+
hooks = {
|
40
|
+
createStylesheet: new SyncWaterfallHook(["source", "chunk"])
|
41
|
+
};
|
42
|
+
compilationHooksMap.set(compilation, hooks);
|
43
|
+
}
|
44
|
+
return hooks;
|
45
|
+
}
|
46
|
+
|
47
|
+
constructor(runtimeRequirements, runtimeOptions) {
|
48
|
+
super("css loading", 10);
|
49
|
+
|
50
|
+
this._runtimeRequirements = runtimeRequirements;
|
51
|
+
this.runtimeOptions = runtimeOptions;
|
52
|
+
}
|
53
|
+
|
54
|
+
/**
|
55
|
+
* @returns {string} runtime code
|
56
|
+
*/
|
57
|
+
generate() {
|
58
|
+
const { compilation, chunk, _runtimeRequirements } = this;
|
59
|
+
const {
|
60
|
+
chunkGraph,
|
61
|
+
runtimeTemplate,
|
62
|
+
outputOptions: {
|
63
|
+
crossOriginLoading,
|
64
|
+
uniqueName,
|
65
|
+
chunkLoadTimeout: loadTimeout
|
66
|
+
}
|
67
|
+
} = compilation;
|
68
|
+
const fn = RuntimeGlobals.ensureChunkHandlers;
|
69
|
+
const conditionMap = chunkGraph.getChunkConditionMap(
|
70
|
+
chunk,
|
71
|
+
(chunk, chunkGraph) =>
|
72
|
+
!!chunkGraph.getChunkModulesIterableBySourceType(chunk, "css")
|
73
|
+
);
|
74
|
+
const hasCssMatcher = compileBooleanMatcher(conditionMap);
|
75
|
+
|
76
|
+
const withLoading =
|
77
|
+
_runtimeRequirements.has(RuntimeGlobals.ensureChunkHandlers) &&
|
78
|
+
hasCssMatcher !== false;
|
79
|
+
const withHmr = _runtimeRequirements.has(
|
80
|
+
RuntimeGlobals.hmrDownloadUpdateHandlers
|
81
|
+
);
|
82
|
+
const initialChunkIdsWithCss = new Set();
|
83
|
+
const initialChunkIdsWithoutCss = new Set();
|
84
|
+
for (const c of chunk.getAllInitialChunks()) {
|
85
|
+
(chunkHasCss(c, chunkGraph)
|
86
|
+
? initialChunkIdsWithCss
|
87
|
+
: initialChunkIdsWithoutCss
|
88
|
+
).add(c.id);
|
89
|
+
}
|
90
|
+
|
91
|
+
if (!withLoading && !withHmr && initialChunkIdsWithCss.size === 0) {
|
92
|
+
return null;
|
93
|
+
}
|
94
|
+
|
95
|
+
const { createStylesheet } =
|
96
|
+
CssLoadingRuntimeModule.getCompilationHooks(compilation);
|
97
|
+
|
98
|
+
const stateExpression = withHmr
|
99
|
+
? `${RuntimeGlobals.hmrRuntimeStatePrefix}_css`
|
100
|
+
: undefined;
|
101
|
+
|
102
|
+
const code = Template.asString([
|
103
|
+
"link = document.createElement('link');",
|
104
|
+
uniqueName
|
105
|
+
? 'link.setAttribute("data-webpack", uniqueName + ":" + key);'
|
106
|
+
: "",
|
107
|
+
"link.setAttribute(loadingAttribute, 1);",
|
108
|
+
'link.rel = "stylesheet";',
|
109
|
+
"link.href = url;",
|
110
|
+
crossOriginLoading
|
111
|
+
? Template.asString([
|
112
|
+
"if (link.src.indexOf(window.location.origin + '/') !== 0) {",
|
113
|
+
Template.indent(
|
114
|
+
`link.crossOrigin = ${JSON.stringify(crossOriginLoading)};`
|
115
|
+
),
|
116
|
+
"}"
|
117
|
+
])
|
118
|
+
: ""
|
119
|
+
]);
|
120
|
+
|
121
|
+
const cc = str => str.charCodeAt(0);
|
122
|
+
|
123
|
+
return Template.asString([
|
124
|
+
"// object to store loaded and loading chunks",
|
125
|
+
"// undefined = chunk not loaded, null = chunk preloaded/prefetched",
|
126
|
+
"// [resolve, reject, Promise] = chunk loading, 0 = chunk loaded",
|
127
|
+
`var installedChunks = ${
|
128
|
+
stateExpression ? `${stateExpression} = ${stateExpression} || ` : ""
|
129
|
+
}{${Array.from(
|
130
|
+
initialChunkIdsWithoutCss,
|
131
|
+
id => `${JSON.stringify(id)}:0`
|
132
|
+
).join(",")}};`,
|
133
|
+
"",
|
134
|
+
uniqueName
|
135
|
+
? `var uniqueName = ${JSON.stringify(
|
136
|
+
runtimeTemplate.outputOptions.uniqueName
|
137
|
+
)};`
|
138
|
+
: "// data-webpack is not used as build has no uniqueName",
|
139
|
+
`var loadCssChunkData = ${runtimeTemplate.basicFunction(
|
140
|
+
"target, link, chunkId",
|
141
|
+
[
|
142
|
+
`var data, token = "", token2, exports = {}, exportsWithId = [], exportsWithDashes = [], ${
|
143
|
+
withHmr ? "moduleIds = [], " : ""
|
144
|
+
}i = 0, cc = 1;`,
|
145
|
+
"try { if(!link) link = loadStylesheet(chunkId); data = link.sheet.cssRules; data = data[data.length - 1].style; } catch(e) { data = getComputedStyle(document.head); }",
|
146
|
+
`data = data.getPropertyValue(${
|
147
|
+
uniqueName
|
148
|
+
? runtimeTemplate.concatenation(
|
149
|
+
"--webpack-",
|
150
|
+
{ expr: "uniqueName" },
|
151
|
+
"-",
|
152
|
+
{ expr: "chunkId" }
|
153
|
+
)
|
154
|
+
: runtimeTemplate.concatenation("--webpack-", { expr: "chunkId" })
|
155
|
+
});`,
|
156
|
+
"if(!data) return [];",
|
157
|
+
"for(; cc; i++) {",
|
158
|
+
Template.indent([
|
159
|
+
"cc = data.charCodeAt(i);",
|
160
|
+
`if(cc == ${cc("(")}) { token2 = token; token = ""; }`,
|
161
|
+
`else if(cc == ${cc(
|
162
|
+
")"
|
163
|
+
)}) { exports[token2.replace(/^_/, "")] = token.replace(/^_/, ""); token = ""; }`,
|
164
|
+
`else if(cc == ${cc("/")} || cc == ${cc(
|
165
|
+
"%"
|
166
|
+
)}) { token = token.replace(/^_/, ""); exports[token] = token; exportsWithId.push(token); if(cc == ${cc(
|
167
|
+
"%"
|
168
|
+
)}) exportsWithDashes.push(token); token = ""; }`,
|
169
|
+
`else if(!cc || cc == ${cc(
|
170
|
+
","
|
171
|
+
)}) { token = token.replace(/^_/, ""); exportsWithId.forEach(${runtimeTemplate.expressionFunction(
|
172
|
+
`exports[x] = ${
|
173
|
+
uniqueName
|
174
|
+
? runtimeTemplate.concatenation(
|
175
|
+
{ expr: "uniqueName" },
|
176
|
+
"-",
|
177
|
+
{ expr: "token" },
|
178
|
+
"-",
|
179
|
+
{ expr: "exports[x]" }
|
180
|
+
)
|
181
|
+
: runtimeTemplate.concatenation({ expr: "token" }, "-", {
|
182
|
+
expr: "exports[x]"
|
183
|
+
})
|
184
|
+
}`,
|
185
|
+
"x"
|
186
|
+
)}); exportsWithDashes.forEach(${runtimeTemplate.expressionFunction(
|
187
|
+
`exports[x] = "--" + exports[x]`,
|
188
|
+
"x"
|
189
|
+
)}); ${
|
190
|
+
RuntimeGlobals.makeNamespaceObject
|
191
|
+
}(exports); target[token] = (${runtimeTemplate.basicFunction(
|
192
|
+
"exports, module",
|
193
|
+
`module.exports = exports;`
|
194
|
+
)}).bind(null, exports); ${
|
195
|
+
withHmr ? "moduleIds.push(token); " : ""
|
196
|
+
}token = ""; exports = {}; exportsWithId.length = 0; }`,
|
197
|
+
`else if(cc == ${cc("\\")}) { token += data[++i] }`,
|
198
|
+
`else { token += data[i]; }`
|
199
|
+
]),
|
200
|
+
"}",
|
201
|
+
`${
|
202
|
+
withHmr ? `if(target == ${RuntimeGlobals.moduleFactories}) ` : ""
|
203
|
+
}installedChunks[chunkId] = 0;`,
|
204
|
+
withHmr ? "return moduleIds;" : ""
|
205
|
+
]
|
206
|
+
)}`,
|
207
|
+
'var loadingAttribute = "data-webpack-loading";',
|
208
|
+
`var loadStylesheet = ${runtimeTemplate.basicFunction(
|
209
|
+
"chunkId, url, done" + (withHmr ? ", hmr" : ""),
|
210
|
+
[
|
211
|
+
'var link, needAttach, key = "chunk-" + chunkId;',
|
212
|
+
withHmr ? "if(!hmr) {" : "",
|
213
|
+
'var links = document.getElementsByTagName("link");',
|
214
|
+
"for(var i = 0; i < links.length; i++) {",
|
215
|
+
Template.indent([
|
216
|
+
"var l = links[i];",
|
217
|
+
`if(l.rel == "stylesheet" && (${
|
218
|
+
withHmr
|
219
|
+
? 'l.href.startsWith(url) || l.getAttribute("href").startsWith(url)'
|
220
|
+
: 'l.href == url || l.getAttribute("href") == url'
|
221
|
+
}${
|
222
|
+
uniqueName
|
223
|
+
? ' || l.getAttribute("data-webpack") == uniqueName + ":" + key'
|
224
|
+
: ""
|
225
|
+
})) { link = l; break; }`
|
226
|
+
]),
|
227
|
+
"}",
|
228
|
+
"if(!done) return link;",
|
229
|
+
withHmr ? "}" : "",
|
230
|
+
"if(!link) {",
|
231
|
+
Template.indent([
|
232
|
+
"needAttach = true;",
|
233
|
+
createStylesheet.call(code, this.chunk)
|
234
|
+
]),
|
235
|
+
"}",
|
236
|
+
`var onLinkComplete = ${runtimeTemplate.basicFunction(
|
237
|
+
"prev, event",
|
238
|
+
Template.asString([
|
239
|
+
"link.onerror = link.onload = null;",
|
240
|
+
"link.removeAttribute(loadingAttribute);",
|
241
|
+
"clearTimeout(timeout);",
|
242
|
+
'if(event && event.type != "load") link.parentNode.removeChild(link)',
|
243
|
+
"done(event);",
|
244
|
+
"if(prev) return prev(event);"
|
245
|
+
])
|
246
|
+
)};`,
|
247
|
+
"if(link.getAttribute(loadingAttribute)) {",
|
248
|
+
Template.indent([
|
249
|
+
`var timeout = setTimeout(onLinkComplete.bind(null, undefined, { type: 'timeout', target: link }), ${loadTimeout});`,
|
250
|
+
"link.onerror = onLinkComplete.bind(null, link.onerror);",
|
251
|
+
"link.onload = onLinkComplete.bind(null, link.onload);"
|
252
|
+
]),
|
253
|
+
"} else onLinkComplete(undefined, { type: 'load', target: link });", // We assume any existing stylesheet is render blocking
|
254
|
+
withHmr ? "hmr ? document.head.insertBefore(link, hmr) :" : "",
|
255
|
+
"needAttach && document.head.appendChild(link);",
|
256
|
+
"return link;"
|
257
|
+
]
|
258
|
+
)};`,
|
259
|
+
initialChunkIdsWithCss.size > 2
|
260
|
+
? `${JSON.stringify(
|
261
|
+
Array.from(initialChunkIdsWithCss)
|
262
|
+
)}.forEach(loadCssChunkData.bind(null, ${
|
263
|
+
RuntimeGlobals.moduleFactories
|
264
|
+
}, 0));`
|
265
|
+
: initialChunkIdsWithCss.size > 0
|
266
|
+
? `${Array.from(
|
267
|
+
initialChunkIdsWithCss,
|
268
|
+
id =>
|
269
|
+
`loadCssChunkData(${
|
270
|
+
RuntimeGlobals.moduleFactories
|
271
|
+
}, 0, ${JSON.stringify(id)});`
|
272
|
+
).join("")}`
|
273
|
+
: "// no initial css",
|
274
|
+
"",
|
275
|
+
withLoading
|
276
|
+
? Template.asString([
|
277
|
+
`${fn}.css = ${runtimeTemplate.basicFunction(
|
278
|
+
"chunkId, promises",
|
279
|
+
hasCssMatcher !== false
|
280
|
+
? [
|
281
|
+
"// css chunk loading",
|
282
|
+
`var installedChunkData = ${RuntimeGlobals.hasOwnProperty}(installedChunks, chunkId) ? installedChunks[chunkId] : undefined;`,
|
283
|
+
'if(installedChunkData !== 0) { // 0 means "already installed".',
|
284
|
+
Template.indent([
|
285
|
+
"",
|
286
|
+
'// a Promise means "currently loading".',
|
287
|
+
"if(installedChunkData) {",
|
288
|
+
Template.indent([
|
289
|
+
"promises.push(installedChunkData[2]);"
|
290
|
+
]),
|
291
|
+
"} else {",
|
292
|
+
Template.indent([
|
293
|
+
hasCssMatcher === true
|
294
|
+
? "if(true) { // all chunks have CSS"
|
295
|
+
: `if(${hasCssMatcher("chunkId")}) {`,
|
296
|
+
Template.indent([
|
297
|
+
"// setup Promise in chunk cache",
|
298
|
+
`var promise = new Promise(${runtimeTemplate.expressionFunction(
|
299
|
+
`installedChunkData = installedChunks[chunkId] = [resolve, reject]`,
|
300
|
+
"resolve, reject"
|
301
|
+
)});`,
|
302
|
+
"promises.push(installedChunkData[2] = promise);",
|
303
|
+
"",
|
304
|
+
"// start chunk loading",
|
305
|
+
`var url = ${RuntimeGlobals.publicPath} + ${RuntimeGlobals.getChunkCssFilename}(chunkId);`,
|
306
|
+
"// create error before stack unwound to get useful stacktrace later",
|
307
|
+
"var error = new Error();",
|
308
|
+
`var loadingEnded = ${runtimeTemplate.basicFunction(
|
309
|
+
"event",
|
310
|
+
[
|
311
|
+
`if(${RuntimeGlobals.hasOwnProperty}(installedChunks, chunkId)) {`,
|
312
|
+
Template.indent([
|
313
|
+
"installedChunkData = installedChunks[chunkId];",
|
314
|
+
"if(installedChunkData !== 0) installedChunks[chunkId] = undefined;",
|
315
|
+
"if(installedChunkData) {",
|
316
|
+
Template.indent([
|
317
|
+
'if(event.type !== "load") {',
|
318
|
+
Template.indent([
|
319
|
+
"var errorType = event && event.type;",
|
320
|
+
"var realSrc = event && event.target && event.target.src;",
|
321
|
+
"error.message = 'Loading css chunk ' + chunkId + ' failed.\\n(' + errorType + ': ' + realSrc + ')';",
|
322
|
+
"error.name = 'ChunkLoadError';",
|
323
|
+
"error.type = errorType;",
|
324
|
+
"error.request = realSrc;",
|
325
|
+
"installedChunkData[1](error);"
|
326
|
+
]),
|
327
|
+
"} else {",
|
328
|
+
Template.indent([
|
329
|
+
`loadCssChunkData(${RuntimeGlobals.moduleFactories}, link, chunkId);`,
|
330
|
+
"installedChunkData[0]();"
|
331
|
+
]),
|
332
|
+
"}"
|
333
|
+
]),
|
334
|
+
"}"
|
335
|
+
]),
|
336
|
+
"}"
|
337
|
+
]
|
338
|
+
)};`,
|
339
|
+
"var link = loadStylesheet(chunkId, url, loadingEnded);"
|
340
|
+
]),
|
341
|
+
"} else installedChunks[chunkId] = 0;"
|
342
|
+
]),
|
343
|
+
"}"
|
344
|
+
]),
|
345
|
+
"}"
|
346
|
+
]
|
347
|
+
: "installedChunks[chunkId] = 0;"
|
348
|
+
)};`
|
349
|
+
])
|
350
|
+
: "// no chunk loading",
|
351
|
+
"",
|
352
|
+
withHmr
|
353
|
+
? Template.asString([
|
354
|
+
"var oldTags = [];",
|
355
|
+
"var newTags = [];",
|
356
|
+
`var applyHandler = ${runtimeTemplate.basicFunction("options", [
|
357
|
+
`return { dispose: ${runtimeTemplate.basicFunction(
|
358
|
+
"",
|
359
|
+
[]
|
360
|
+
)}, apply: ${runtimeTemplate.basicFunction("", [
|
361
|
+
"var moduleIds = [];",
|
362
|
+
`newTags.forEach(${runtimeTemplate.expressionFunction(
|
363
|
+
"info[1].sheet.disabled = false",
|
364
|
+
"info"
|
365
|
+
)});`,
|
366
|
+
"while(oldTags.length) {",
|
367
|
+
Template.indent([
|
368
|
+
"var oldTag = oldTags.pop();",
|
369
|
+
"if(oldTag.parentNode) oldTag.parentNode.removeChild(oldTag);"
|
370
|
+
]),
|
371
|
+
"}",
|
372
|
+
"while(newTags.length) {",
|
373
|
+
Template.indent([
|
374
|
+
`var info = newTags.pop();`,
|
375
|
+
`var chunkModuleIds = loadCssChunkData(${RuntimeGlobals.moduleFactories}, info[1], info[0]);`,
|
376
|
+
`chunkModuleIds.forEach(${runtimeTemplate.expressionFunction(
|
377
|
+
"moduleIds.push(id)",
|
378
|
+
"id"
|
379
|
+
)});`
|
380
|
+
]),
|
381
|
+
"}",
|
382
|
+
"return moduleIds;"
|
383
|
+
])} };`
|
384
|
+
])}`,
|
385
|
+
`var cssTextKey = ${runtimeTemplate.returningFunction(
|
386
|
+
`Array.from(link.sheet.cssRules, ${runtimeTemplate.returningFunction(
|
387
|
+
"r.cssText",
|
388
|
+
"r"
|
389
|
+
)}).join()`,
|
390
|
+
"link"
|
391
|
+
)}`,
|
392
|
+
`${
|
393
|
+
RuntimeGlobals.hmrDownloadUpdateHandlers
|
394
|
+
}.css = ${runtimeTemplate.basicFunction(
|
395
|
+
"chunkIds, removedChunks, removedModules, promises, applyHandlers, updatedModulesList",
|
396
|
+
[
|
397
|
+
"applyHandlers.push(applyHandler);",
|
398
|
+
`chunkIds.forEach(${runtimeTemplate.basicFunction("chunkId", [
|
399
|
+
`var filename = ${RuntimeGlobals.getChunkCssFilename}(chunkId);`,
|
400
|
+
`var url = ${RuntimeGlobals.publicPath} + filename;`,
|
401
|
+
"var oldTag = loadStylesheet(chunkId, url);",
|
402
|
+
"if(!oldTag) return;",
|
403
|
+
`promises.push(new Promise(${runtimeTemplate.basicFunction(
|
404
|
+
"resolve, reject",
|
405
|
+
[
|
406
|
+
`var link = loadStylesheet(chunkId, url + (url.indexOf("?") < 0 ? "?" : "&") + "hmr=" + Date.now(), ${runtimeTemplate.basicFunction(
|
407
|
+
"event",
|
408
|
+
[
|
409
|
+
'if(event.type !== "load") {',
|
410
|
+
Template.indent([
|
411
|
+
"var errorType = event && event.type;",
|
412
|
+
"var realSrc = event && event.target && event.target.src;",
|
413
|
+
"error.message = 'Loading css hot update chunk ' + chunkId + ' failed.\\n(' + errorType + ': ' + realSrc + ')';",
|
414
|
+
"error.name = 'ChunkLoadError';",
|
415
|
+
"error.type = errorType;",
|
416
|
+
"error.request = realSrc;",
|
417
|
+
"reject(error);"
|
418
|
+
]),
|
419
|
+
"} else {",
|
420
|
+
Template.indent([
|
421
|
+
"try { if(cssTextKey(oldTag) == cssTextKey(link)) { if(link.parentNode) link.parentNode.removeChild(link); return resolve(); } } catch(e) {}",
|
422
|
+
"var factories = {};",
|
423
|
+
"loadCssChunkData(factories, link, chunkId);",
|
424
|
+
`Object.keys(factories).forEach(${runtimeTemplate.expressionFunction(
|
425
|
+
"updatedModulesList.push(id)",
|
426
|
+
"id"
|
427
|
+
)})`,
|
428
|
+
"link.sheet.disabled = true;",
|
429
|
+
"oldTags.push(oldTag);",
|
430
|
+
"newTags.push([chunkId, link]);",
|
431
|
+
"resolve();"
|
432
|
+
]),
|
433
|
+
"}"
|
434
|
+
]
|
435
|
+
)}, oldTag);`
|
436
|
+
]
|
437
|
+
)}));`
|
438
|
+
])});`
|
439
|
+
]
|
440
|
+
)}`
|
441
|
+
])
|
442
|
+
: "// no hmr"
|
443
|
+
]);
|
444
|
+
}
|
445
|
+
}
|
446
|
+
|
447
|
+
module.exports = CssLoadingRuntimeModule;
|