mirror of https://github.com/webpack/webpack.git
fix: avoid extra runtime for get javascript/css chunk filename
This commit is contained in:
parent
fcd41d21be
commit
9ad073028e
|
@ -34,6 +34,12 @@ const RuntimeIdRuntimeModule = require("./runtime/RuntimeIdRuntimeModule");
|
||||||
const SystemContextRuntimeModule = require("./runtime/SystemContextRuntimeModule");
|
const SystemContextRuntimeModule = require("./runtime/SystemContextRuntimeModule");
|
||||||
const ShareRuntimeModule = require("./sharing/ShareRuntimeModule");
|
const ShareRuntimeModule = require("./sharing/ShareRuntimeModule");
|
||||||
const StringXor = require("./util/StringXor");
|
const StringXor = require("./util/StringXor");
|
||||||
|
const memoize = require("./util/memoize");
|
||||||
|
|
||||||
|
const getJavascriptModulesPlugin = memoize(() =>
|
||||||
|
require("./javascript/JavascriptModulesPlugin")
|
||||||
|
);
|
||||||
|
const getCssModulesPlugin = memoize(() => require("./css/CssModulesPlugin"));
|
||||||
|
|
||||||
/** @typedef {import("../declarations/WebpackOptions").LibraryOptions} LibraryOptions */
|
/** @typedef {import("../declarations/WebpackOptions").LibraryOptions} LibraryOptions */
|
||||||
/** @typedef {import("../declarations/WebpackOptions").OutputNormalized} OutputNormalized */
|
/** @typedef {import("../declarations/WebpackOptions").OutputNormalized} OutputNormalized */
|
||||||
|
@ -261,7 +267,7 @@ class RuntimePlugin {
|
||||||
});
|
});
|
||||||
compilation.hooks.runtimeRequirementInTree
|
compilation.hooks.runtimeRequirementInTree
|
||||||
.for(RuntimeGlobals.getChunkScriptFilename)
|
.for(RuntimeGlobals.getChunkScriptFilename)
|
||||||
.tap("RuntimePlugin", (chunk, set) => {
|
.tap("RuntimePlugin", (chunk, set, { chunkGraph }) => {
|
||||||
if (
|
if (
|
||||||
typeof compilation.outputOptions.chunkFilename === "string" &&
|
typeof compilation.outputOptions.chunkFilename === "string" &&
|
||||||
/\[(full)?hash(:\d+)?\]/.test(
|
/\[(full)?hash(:\d+)?\]/.test(
|
||||||
|
@ -279,10 +285,11 @@ class RuntimePlugin {
|
||||||
chunk =>
|
chunk =>
|
||||||
/** @type {TemplatePath} */
|
/** @type {TemplatePath} */
|
||||||
(
|
(
|
||||||
chunk.filenameTemplate ||
|
getJavascriptModulesPlugin().chunkHasJs(chunk, chunkGraph) &&
|
||||||
(chunk.canBeInitial()
|
(chunk.filenameTemplate ||
|
||||||
? compilation.outputOptions.filename
|
(chunk.canBeInitial()
|
||||||
: compilation.outputOptions.chunkFilename)
|
? compilation.outputOptions.filename
|
||||||
|
: compilation.outputOptions.chunkFilename))
|
||||||
),
|
),
|
||||||
false
|
false
|
||||||
)
|
)
|
||||||
|
@ -291,7 +298,7 @@ class RuntimePlugin {
|
||||||
});
|
});
|
||||||
compilation.hooks.runtimeRequirementInTree
|
compilation.hooks.runtimeRequirementInTree
|
||||||
.for(RuntimeGlobals.getChunkCssFilename)
|
.for(RuntimeGlobals.getChunkCssFilename)
|
||||||
.tap("RuntimePlugin", (chunk, set) => {
|
.tap("RuntimePlugin", (chunk, set, { chunkGraph }) => {
|
||||||
if (
|
if (
|
||||||
typeof compilation.outputOptions.cssChunkFilename === "string" &&
|
typeof compilation.outputOptions.cssChunkFilename === "string" &&
|
||||||
/\[(full)?hash(:\d+)?\]/.test(
|
/\[(full)?hash(:\d+)?\]/.test(
|
||||||
|
@ -307,6 +314,7 @@ class RuntimePlugin {
|
||||||
"css",
|
"css",
|
||||||
RuntimeGlobals.getChunkCssFilename,
|
RuntimeGlobals.getChunkCssFilename,
|
||||||
chunk =>
|
chunk =>
|
||||||
|
getCssModulesPlugin().chunkHasCss(chunk, chunkGraph) &&
|
||||||
getChunkFilenameTemplate(chunk, compilation.outputOptions),
|
getChunkFilenameTemplate(chunk, compilation.outputOptions),
|
||||||
set.has(RuntimeGlobals.hmrDownloadUpdateHandlers)
|
set.has(RuntimeGlobals.hmrDownloadUpdateHandlers)
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue