generated from dellevin/template
1
This commit is contained in:
30
node_modules/webpack/lib/esm/ExportWebpackRequireRuntimeModule.js
generated
vendored
Normal file
30
node_modules/webpack/lib/esm/ExportWebpackRequireRuntimeModule.js
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
const RuntimeGlobals = require("../RuntimeGlobals");
|
||||
const RuntimeModule = require("../RuntimeModule");
|
||||
|
||||
class ExportWebpackRequireRuntimeModule extends RuntimeModule {
|
||||
constructor() {
|
||||
super("export webpack runtime", RuntimeModule.STAGE_ATTACH);
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {boolean} true, if the runtime module should get it's own scope
|
||||
*/
|
||||
shouldIsolate() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {string | null} runtime code
|
||||
*/
|
||||
generate() {
|
||||
return `export { ${RuntimeGlobals.require} };`;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ExportWebpackRequireRuntimeModule;
|
||||
273
node_modules/webpack/lib/esm/ModuleChunkFormatPlugin.js
generated
vendored
Normal file
273
node_modules/webpack/lib/esm/ModuleChunkFormatPlugin.js
generated
vendored
Normal file
@@ -0,0 +1,273 @@
|
||||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
const { ConcatSource } = require("webpack-sources");
|
||||
const { HotUpdateChunk, RuntimeGlobals } = require("..");
|
||||
const { JAVASCRIPT_TYPE } = require("../ModuleSourceTypeConstants");
|
||||
const Template = require("../Template");
|
||||
const {
|
||||
createChunkHashHandler,
|
||||
getChunkInfo
|
||||
} = require("../javascript/ChunkFormatHelpers");
|
||||
const { getAllChunks } = require("../javascript/ChunkHelpers");
|
||||
const {
|
||||
chunkHasJs,
|
||||
getChunkFilenameTemplate,
|
||||
getCompilationHooks
|
||||
} = require("../javascript/JavascriptModulesPlugin");
|
||||
const { getUndoPath } = require("../util/identifier");
|
||||
|
||||
/** @typedef {import("webpack-sources").Source} Source */
|
||||
/** @typedef {import("../Chunk")} Chunk */
|
||||
/** @typedef {import("../ChunkGraph")} ChunkGraph */
|
||||
/** @typedef {import("../Compilation")} Compilation */
|
||||
/** @typedef {import("../Compiler")} Compiler */
|
||||
/** @typedef {import("../Entrypoint")} Entrypoint */
|
||||
|
||||
/**
|
||||
* @param {Compilation} compilation the compilation instance
|
||||
* @param {Chunk} chunk the chunk
|
||||
* @param {Chunk} runtimeChunk the runtime chunk
|
||||
* @returns {string} the relative path
|
||||
*/
|
||||
const getRelativePath = (compilation, chunk, runtimeChunk) => {
|
||||
const currentOutputName = compilation
|
||||
.getPath(
|
||||
getChunkFilenameTemplate(runtimeChunk, compilation.outputOptions),
|
||||
{
|
||||
chunk: runtimeChunk,
|
||||
contentHashType: "javascript"
|
||||
}
|
||||
)
|
||||
.replace(/^\/+/g, "")
|
||||
.split("/");
|
||||
const baseOutputName = [...currentOutputName];
|
||||
const chunkOutputName = compilation
|
||||
.getPath(getChunkFilenameTemplate(chunk, compilation.outputOptions), {
|
||||
chunk,
|
||||
contentHashType: "javascript"
|
||||
})
|
||||
.replace(/^\/+/g, "")
|
||||
.split("/");
|
||||
|
||||
// remove common parts except filename
|
||||
while (
|
||||
baseOutputName.length > 1 &&
|
||||
chunkOutputName.length > 1 &&
|
||||
baseOutputName[0] === chunkOutputName[0]
|
||||
) {
|
||||
baseOutputName.shift();
|
||||
chunkOutputName.shift();
|
||||
}
|
||||
const last = chunkOutputName.join("/");
|
||||
// create final path
|
||||
return getUndoPath(baseOutputName.join("/"), last, true) + last;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Compilation} compilation the compilation instance
|
||||
* @param {Chunk} chunk the chunk to render the import for
|
||||
* @param {string=} namedImport the named import to use for the import
|
||||
* @param {Chunk=} runtimeChunk the runtime chunk
|
||||
* @returns {string} the import source
|
||||
*/
|
||||
function renderChunkImport(compilation, chunk, namedImport, runtimeChunk) {
|
||||
return `import ${namedImport ? `* as ${namedImport}` : `{ ${RuntimeGlobals.require} }`} from ${JSON.stringify(
|
||||
getRelativePath(compilation, chunk, runtimeChunk || chunk)
|
||||
)};\n`;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {number} index the index of the chunk
|
||||
* @returns {string} the named import to use for the import
|
||||
*/
|
||||
function getChunkNamedImport(index) {
|
||||
return `__webpack_chunk_${index}__`;
|
||||
}
|
||||
|
||||
const PLUGIN_NAME = "ModuleChunkFormatPlugin";
|
||||
|
||||
class ModuleChunkFormatPlugin {
|
||||
/**
|
||||
* Apply the plugin
|
||||
* @param {Compiler} compiler the compiler instance
|
||||
* @returns {void}
|
||||
*/
|
||||
apply(compiler) {
|
||||
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
|
||||
compilation.hooks.additionalChunkRuntimeRequirements.tap(
|
||||
PLUGIN_NAME,
|
||||
(chunk, set) => {
|
||||
if (chunk.hasRuntime()) return;
|
||||
if (compilation.chunkGraph.getNumberOfEntryModules(chunk) > 0) {
|
||||
set.add(RuntimeGlobals.require);
|
||||
set.add(RuntimeGlobals.externalInstallChunk);
|
||||
}
|
||||
}
|
||||
);
|
||||
const hooks = getCompilationHooks(compilation);
|
||||
/**
|
||||
* @param {Iterable<Chunk>} chunks the chunks to render
|
||||
* @param {ChunkGraph} chunkGraph the chunk graph
|
||||
* @param {Chunk=} runtimeChunk the runtime chunk
|
||||
* @returns {Source | undefined} the source
|
||||
*/
|
||||
const withDependentChunks = (chunks, chunkGraph, runtimeChunk) => {
|
||||
if (/** @type {Set<Chunk>} */ (chunks).size > 0) {
|
||||
const source = new ConcatSource();
|
||||
let index = 0;
|
||||
|
||||
for (const chunk of chunks) {
|
||||
index++;
|
||||
|
||||
if (!chunkHasJs(chunk, chunkGraph)) {
|
||||
continue;
|
||||
}
|
||||
const namedImport = getChunkNamedImport(index);
|
||||
source.add(
|
||||
renderChunkImport(
|
||||
compilation,
|
||||
chunk,
|
||||
namedImport,
|
||||
runtimeChunk || chunk
|
||||
)
|
||||
);
|
||||
source.add(
|
||||
`${RuntimeGlobals.externalInstallChunk}(${namedImport});\n`
|
||||
);
|
||||
}
|
||||
return source;
|
||||
}
|
||||
};
|
||||
hooks.renderStartup.tap(
|
||||
PLUGIN_NAME,
|
||||
(modules, _lastModule, renderContext) => {
|
||||
const { chunk, chunkGraph } = renderContext;
|
||||
if (
|
||||
chunkGraph.getNumberOfEntryModules(chunk) > 0 &&
|
||||
chunk.hasRuntime()
|
||||
) {
|
||||
const entryDependentChunks =
|
||||
chunkGraph.getChunkEntryDependentChunksIterable(chunk);
|
||||
const sourceWithDependentChunks = withDependentChunks(
|
||||
entryDependentChunks,
|
||||
chunkGraph,
|
||||
chunk
|
||||
);
|
||||
if (!sourceWithDependentChunks) {
|
||||
return modules;
|
||||
}
|
||||
if (modules.size() === 0) {
|
||||
return sourceWithDependentChunks;
|
||||
}
|
||||
const source = new ConcatSource();
|
||||
source.add(sourceWithDependentChunks);
|
||||
source.add("\n");
|
||||
source.add(modules);
|
||||
return source;
|
||||
}
|
||||
return modules;
|
||||
}
|
||||
);
|
||||
hooks.renderChunk.tap(PLUGIN_NAME, (modules, renderContext) => {
|
||||
const { chunk, chunkGraph, runtimeTemplate } = renderContext;
|
||||
const hotUpdateChunk = chunk instanceof HotUpdateChunk ? chunk : null;
|
||||
const source = new ConcatSource();
|
||||
source.add(
|
||||
`export const ${RuntimeGlobals.esmId} = ${JSON.stringify(chunk.id)};\n`
|
||||
);
|
||||
source.add(
|
||||
`export const ${RuntimeGlobals.esmIds} = ${JSON.stringify(chunk.ids)};\n`
|
||||
);
|
||||
source.add(`export const ${RuntimeGlobals.esmModules} = `);
|
||||
source.add(modules);
|
||||
source.add(";\n");
|
||||
const runtimeModules = chunkGraph.getChunkRuntimeModulesInOrder(chunk);
|
||||
if (runtimeModules.length > 0) {
|
||||
source.add(`export const ${RuntimeGlobals.esmRuntime} =\n`);
|
||||
source.add(
|
||||
Template.renderChunkRuntimeModules(runtimeModules, renderContext)
|
||||
);
|
||||
}
|
||||
if (hotUpdateChunk) {
|
||||
return source;
|
||||
}
|
||||
const { entries, runtimeChunk } = getChunkInfo(chunk, chunkGraph);
|
||||
if (runtimeChunk) {
|
||||
const entrySource = new ConcatSource();
|
||||
entrySource.add(source);
|
||||
entrySource.add(";\n\n// load runtime\n");
|
||||
entrySource.add(
|
||||
renderChunkImport(compilation, runtimeChunk, "", chunk)
|
||||
);
|
||||
const startupSource = new ConcatSource();
|
||||
startupSource.add(
|
||||
`var __webpack_exec__ = ${runtimeTemplate.returningFunction(
|
||||
`${RuntimeGlobals.require}(${RuntimeGlobals.entryModuleId} = moduleId)`,
|
||||
"moduleId"
|
||||
)}\n`
|
||||
);
|
||||
|
||||
/** @type {Set<Chunk>} */
|
||||
const loadedChunks = new Set();
|
||||
for (let i = 0; i < entries.length; i++) {
|
||||
const [module, entrypoint] = entries[i];
|
||||
if (!chunkGraph.getModuleSourceTypes(module).has(JAVASCRIPT_TYPE)) {
|
||||
continue;
|
||||
}
|
||||
const final = i + 1 === entries.length;
|
||||
const moduleId = chunkGraph.getModuleId(module);
|
||||
const chunks = getAllChunks(
|
||||
/** @type {Entrypoint} */ (entrypoint),
|
||||
/** @type {Chunk} */ (runtimeChunk),
|
||||
undefined
|
||||
);
|
||||
/** @type {Set<Chunk>} */
|
||||
const processChunks = new Set();
|
||||
for (const chunk of chunks) {
|
||||
if (loadedChunks.has(chunk)) {
|
||||
continue;
|
||||
}
|
||||
loadedChunks.add(chunk);
|
||||
processChunks.add(chunk);
|
||||
}
|
||||
const sourceWithDependentChunks = withDependentChunks(
|
||||
processChunks,
|
||||
chunkGraph,
|
||||
chunk
|
||||
);
|
||||
if (sourceWithDependentChunks) {
|
||||
startupSource.add("\n");
|
||||
startupSource.add(sourceWithDependentChunks);
|
||||
}
|
||||
startupSource.add(
|
||||
`${
|
||||
final ? `var ${RuntimeGlobals.exports} = ` : ""
|
||||
}__webpack_exec__(${JSON.stringify(moduleId)});\n`
|
||||
);
|
||||
}
|
||||
|
||||
entrySource.add(
|
||||
hooks.renderStartup.call(
|
||||
startupSource,
|
||||
entries[entries.length - 1][0],
|
||||
{
|
||||
...renderContext,
|
||||
inlined: false
|
||||
}
|
||||
)
|
||||
);
|
||||
return entrySource;
|
||||
}
|
||||
return source;
|
||||
});
|
||||
hooks.chunkHash.tap(PLUGIN_NAME, createChunkHashHandler(PLUGIN_NAME));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ModuleChunkFormatPlugin;
|
||||
143
node_modules/webpack/lib/esm/ModuleChunkLoadingPlugin.js
generated
vendored
Normal file
143
node_modules/webpack/lib/esm/ModuleChunkLoadingPlugin.js
generated
vendored
Normal file
@@ -0,0 +1,143 @@
|
||||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
const RuntimeGlobals = require("../RuntimeGlobals");
|
||||
const ExportWebpackRequireRuntimeModule = require("./ExportWebpackRequireRuntimeModule");
|
||||
const ModuleChunkLoadingRuntimeModule = require("./ModuleChunkLoadingRuntimeModule");
|
||||
|
||||
/** @typedef {import("../Chunk")} Chunk */
|
||||
/** @typedef {import("../Compiler")} Compiler */
|
||||
/** @typedef {import("../Module").RuntimeRequirements} RuntimeRequirements */
|
||||
|
||||
const PLUGIN_NAME = "ModuleChunkLoadingPlugin";
|
||||
|
||||
class ModuleChunkLoadingPlugin {
|
||||
/**
|
||||
* Apply the plugin
|
||||
* @param {Compiler} compiler the compiler instance
|
||||
* @returns {void}
|
||||
*/
|
||||
apply(compiler) {
|
||||
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
|
||||
const globalChunkLoading = compilation.outputOptions.chunkLoading;
|
||||
/**
|
||||
* @param {Chunk} chunk chunk to check
|
||||
* @returns {boolean} true, when the plugin is enabled for the chunk
|
||||
*/
|
||||
const isEnabledForChunk = (chunk) => {
|
||||
const options = chunk.getEntryOptions();
|
||||
const chunkLoading =
|
||||
options && options.chunkLoading !== undefined
|
||||
? options.chunkLoading
|
||||
: globalChunkLoading;
|
||||
return chunkLoading === "import";
|
||||
};
|
||||
/** @type {WeakSet<Chunk>} */
|
||||
const onceForChunkSet = new WeakSet();
|
||||
/**
|
||||
* @param {Chunk} chunk chunk to check
|
||||
* @param {RuntimeRequirements} set runtime requirements
|
||||
*/
|
||||
const handler = (chunk, set) => {
|
||||
if (onceForChunkSet.has(chunk)) return;
|
||||
onceForChunkSet.add(chunk);
|
||||
if (!isEnabledForChunk(chunk)) return;
|
||||
set.add(RuntimeGlobals.moduleFactoriesAddOnly);
|
||||
set.add(RuntimeGlobals.hasOwnProperty);
|
||||
compilation.addRuntimeModule(
|
||||
chunk,
|
||||
new ModuleChunkLoadingRuntimeModule(set)
|
||||
);
|
||||
};
|
||||
compilation.hooks.runtimeRequirementInTree
|
||||
.for(RuntimeGlobals.ensureChunkHandlers)
|
||||
.tap(PLUGIN_NAME, handler);
|
||||
compilation.hooks.runtimeRequirementInTree
|
||||
.for(RuntimeGlobals.baseURI)
|
||||
.tap(PLUGIN_NAME, handler);
|
||||
compilation.hooks.runtimeRequirementInTree
|
||||
.for(RuntimeGlobals.externalInstallChunk)
|
||||
.tap(PLUGIN_NAME, handler);
|
||||
compilation.hooks.runtimeRequirementInTree
|
||||
.for(RuntimeGlobals.onChunksLoaded)
|
||||
.tap(PLUGIN_NAME, handler);
|
||||
compilation.hooks.runtimeRequirementInTree
|
||||
.for(RuntimeGlobals.hmrDownloadUpdateHandlers)
|
||||
.tap(PLUGIN_NAME, handler);
|
||||
compilation.hooks.runtimeRequirementInTree
|
||||
.for(RuntimeGlobals.hmrDownloadManifest)
|
||||
.tap(PLUGIN_NAME, handler);
|
||||
compilation.hooks.runtimeRequirementInTree
|
||||
.for(RuntimeGlobals.externalInstallChunk)
|
||||
.tap(PLUGIN_NAME, (chunk) => {
|
||||
if (!isEnabledForChunk(chunk)) return;
|
||||
compilation.addRuntimeModule(
|
||||
chunk,
|
||||
new ExportWebpackRequireRuntimeModule()
|
||||
);
|
||||
});
|
||||
|
||||
// We need public path only when we prefetch/preload chunk or public path is not `auto`
|
||||
compilation.hooks.runtimeRequirementInTree
|
||||
.for(RuntimeGlobals.prefetchChunkHandlers)
|
||||
.tap(PLUGIN_NAME, (chunk, set) => {
|
||||
if (!isEnabledForChunk(chunk)) return;
|
||||
set.add(RuntimeGlobals.publicPath);
|
||||
});
|
||||
|
||||
compilation.hooks.runtimeRequirementInTree
|
||||
.for(RuntimeGlobals.preloadChunkHandlers)
|
||||
.tap(PLUGIN_NAME, (chunk, set) => {
|
||||
if (!isEnabledForChunk(chunk)) return;
|
||||
set.add(RuntimeGlobals.publicPath);
|
||||
});
|
||||
|
||||
compilation.hooks.runtimeRequirementInTree
|
||||
.for(RuntimeGlobals.ensureChunkHandlers)
|
||||
.tap(PLUGIN_NAME, (chunk, set) => {
|
||||
if (!isEnabledForChunk(chunk)) return;
|
||||
|
||||
if (compilation.outputOptions.publicPath !== "auto") {
|
||||
set.add(RuntimeGlobals.publicPath);
|
||||
}
|
||||
|
||||
set.add(RuntimeGlobals.getChunkScriptFilename);
|
||||
});
|
||||
|
||||
compilation.hooks.runtimeRequirementInTree
|
||||
.for(RuntimeGlobals.hmrDownloadUpdateHandlers)
|
||||
.tap(PLUGIN_NAME, (chunk, set) => {
|
||||
if (!isEnabledForChunk(chunk)) return;
|
||||
set.add(RuntimeGlobals.publicPath);
|
||||
set.add(RuntimeGlobals.loadScript);
|
||||
set.add(RuntimeGlobals.getChunkUpdateScriptFilename);
|
||||
set.add(RuntimeGlobals.moduleCache);
|
||||
set.add(RuntimeGlobals.hmrModuleData);
|
||||
set.add(RuntimeGlobals.moduleFactoriesAddOnly);
|
||||
});
|
||||
|
||||
compilation.hooks.runtimeRequirementInTree
|
||||
.for(RuntimeGlobals.hmrDownloadManifest)
|
||||
.tap(PLUGIN_NAME, (chunk, set) => {
|
||||
if (!isEnabledForChunk(chunk)) return;
|
||||
set.add(RuntimeGlobals.publicPath);
|
||||
set.add(RuntimeGlobals.getUpdateManifestFilename);
|
||||
});
|
||||
|
||||
compilation.hooks.additionalTreeRuntimeRequirements.tap(
|
||||
PLUGIN_NAME,
|
||||
(chunk, set, { chunkGraph }) => {
|
||||
if (chunkGraph.hasChunkEntryDependentChunks(chunk)) {
|
||||
set.add(RuntimeGlobals.externalInstallChunk);
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ModuleChunkLoadingPlugin;
|
||||
426
node_modules/webpack/lib/esm/ModuleChunkLoadingRuntimeModule.js
generated
vendored
Normal file
426
node_modules/webpack/lib/esm/ModuleChunkLoadingRuntimeModule.js
generated
vendored
Normal file
@@ -0,0 +1,426 @@
|
||||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
const { SyncWaterfallHook } = require("tapable");
|
||||
const Compilation = require("../Compilation");
|
||||
const RuntimeGlobals = require("../RuntimeGlobals");
|
||||
const RuntimeModule = require("../RuntimeModule");
|
||||
const Template = require("../Template");
|
||||
const {
|
||||
generateJavascriptHMR
|
||||
} = require("../hmr/JavascriptHotModuleReplacementHelper");
|
||||
const {
|
||||
chunkHasJs,
|
||||
getChunkFilenameTemplate
|
||||
} = require("../javascript/JavascriptModulesPlugin");
|
||||
const { getInitialChunkIds } = require("../javascript/StartupHelpers");
|
||||
const compileBooleanMatcher = require("../util/compileBooleanMatcher");
|
||||
const { getUndoPath } = require("../util/identifier");
|
||||
|
||||
/** @typedef {import("../Chunk")} Chunk */
|
||||
/** @typedef {import("../ChunkGraph")} ChunkGraph */
|
||||
/** @typedef {import("../Module").ReadOnlyRuntimeRequirements} ReadOnlyRuntimeRequirements */
|
||||
|
||||
/**
|
||||
* @typedef {object} JsonpCompilationPluginHooks
|
||||
* @property {SyncWaterfallHook<[string, Chunk]>} linkPreload
|
||||
* @property {SyncWaterfallHook<[string, Chunk]>} linkPrefetch
|
||||
*/
|
||||
|
||||
/** @type {WeakMap<Compilation, JsonpCompilationPluginHooks>} */
|
||||
const compilationHooksMap = new WeakMap();
|
||||
|
||||
class ModuleChunkLoadingRuntimeModule extends RuntimeModule {
|
||||
/**
|
||||
* @param {Compilation} compilation the compilation
|
||||
* @returns {JsonpCompilationPluginHooks} hooks
|
||||
*/
|
||||
static getCompilationHooks(compilation) {
|
||||
if (!(compilation instanceof Compilation)) {
|
||||
throw new TypeError(
|
||||
"The 'compilation' argument must be an instance of Compilation"
|
||||
);
|
||||
}
|
||||
let hooks = compilationHooksMap.get(compilation);
|
||||
if (hooks === undefined) {
|
||||
hooks = {
|
||||
linkPreload: new SyncWaterfallHook(["source", "chunk"]),
|
||||
linkPrefetch: new SyncWaterfallHook(["source", "chunk"])
|
||||
};
|
||||
compilationHooksMap.set(compilation, hooks);
|
||||
}
|
||||
return hooks;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {ReadOnlyRuntimeRequirements} runtimeRequirements runtime requirements
|
||||
*/
|
||||
constructor(runtimeRequirements) {
|
||||
super("import chunk loading", RuntimeModule.STAGE_ATTACH);
|
||||
/** @type {ReadOnlyRuntimeRequirements} */
|
||||
this._runtimeRequirements = runtimeRequirements;
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {Chunk} chunk chunk
|
||||
* @param {string} rootOutputDir root output directory
|
||||
* @returns {string} generated code
|
||||
*/
|
||||
_generateBaseUri(chunk, rootOutputDir) {
|
||||
const options = chunk.getEntryOptions();
|
||||
if (options && options.baseUri) {
|
||||
return `${RuntimeGlobals.baseURI} = ${JSON.stringify(options.baseUri)};`;
|
||||
}
|
||||
const compilation = /** @type {Compilation} */ (this.compilation);
|
||||
const {
|
||||
outputOptions: { importMetaName }
|
||||
} = compilation;
|
||||
return `${RuntimeGlobals.baseURI} = new URL(${JSON.stringify(
|
||||
rootOutputDir
|
||||
)}, ${importMetaName}.url);`;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {string | null} runtime code
|
||||
*/
|
||||
generate() {
|
||||
const compilation = /** @type {Compilation} */ (this.compilation);
|
||||
const chunkGraph = /** @type {ChunkGraph} */ (this.chunkGraph);
|
||||
const chunk = /** @type {Chunk} */ (this.chunk);
|
||||
const environment = compilation.outputOptions.environment;
|
||||
const {
|
||||
runtimeTemplate,
|
||||
outputOptions: { importFunctionName, crossOriginLoading, charset }
|
||||
} = compilation;
|
||||
const fn = RuntimeGlobals.ensureChunkHandlers;
|
||||
const withBaseURI = this._runtimeRequirements.has(RuntimeGlobals.baseURI);
|
||||
const withExternalInstallChunk = this._runtimeRequirements.has(
|
||||
RuntimeGlobals.externalInstallChunk
|
||||
);
|
||||
const withLoading = this._runtimeRequirements.has(
|
||||
RuntimeGlobals.ensureChunkHandlers
|
||||
);
|
||||
const withOnChunkLoad = this._runtimeRequirements.has(
|
||||
RuntimeGlobals.onChunksLoaded
|
||||
);
|
||||
const withHmr = this._runtimeRequirements.has(
|
||||
RuntimeGlobals.hmrDownloadUpdateHandlers
|
||||
);
|
||||
const withHmrManifest = this._runtimeRequirements.has(
|
||||
RuntimeGlobals.hmrDownloadManifest
|
||||
);
|
||||
const { linkPreload, linkPrefetch } =
|
||||
ModuleChunkLoadingRuntimeModule.getCompilationHooks(compilation);
|
||||
const isNeutralPlatform = runtimeTemplate.isNeutralPlatform();
|
||||
const withPrefetch =
|
||||
(environment.document || isNeutralPlatform) &&
|
||||
this._runtimeRequirements.has(RuntimeGlobals.prefetchChunkHandlers) &&
|
||||
chunk.hasChildByOrder(chunkGraph, "prefetch", true, chunkHasJs);
|
||||
const withPreload =
|
||||
(environment.document || isNeutralPlatform) &&
|
||||
this._runtimeRequirements.has(RuntimeGlobals.preloadChunkHandlers) &&
|
||||
chunk.hasChildByOrder(chunkGraph, "preload", true, chunkHasJs);
|
||||
const conditionMap = chunkGraph.getChunkConditionMap(chunk, chunkHasJs);
|
||||
const hasJsMatcher = compileBooleanMatcher(conditionMap);
|
||||
const initialChunkIds = getInitialChunkIds(chunk, chunkGraph, chunkHasJs);
|
||||
|
||||
const outputName = compilation.getPath(
|
||||
getChunkFilenameTemplate(chunk, compilation.outputOptions),
|
||||
{
|
||||
chunk,
|
||||
contentHashType: "javascript"
|
||||
}
|
||||
);
|
||||
const rootOutputDir = getUndoPath(
|
||||
outputName,
|
||||
compilation.outputOptions.path,
|
||||
true
|
||||
);
|
||||
|
||||
const stateExpression = withHmr
|
||||
? `${RuntimeGlobals.hmrRuntimeStatePrefix}_module`
|
||||
: undefined;
|
||||
|
||||
return Template.asString([
|
||||
withBaseURI
|
||||
? this._generateBaseUri(chunk, rootOutputDir)
|
||||
: "// no baseURI",
|
||||
"",
|
||||
"// object to store loaded and loading chunks",
|
||||
"// undefined = chunk not loaded, null = chunk preloaded/prefetched",
|
||||
"// [resolve, Promise] = chunk loading, 0 = chunk loaded",
|
||||
`var installedChunks = ${
|
||||
stateExpression ? `${stateExpression} = ${stateExpression} || ` : ""
|
||||
}{`,
|
||||
Template.indent(
|
||||
Array.from(initialChunkIds, (id) => `${JSON.stringify(id)}: 0`).join(
|
||||
",\n"
|
||||
)
|
||||
),
|
||||
"};",
|
||||
"",
|
||||
withLoading || withExternalInstallChunk
|
||||
? `var installChunk = ${runtimeTemplate.basicFunction("data", [
|
||||
runtimeTemplate.destructureObject(
|
||||
[
|
||||
RuntimeGlobals.esmIds,
|
||||
RuntimeGlobals.esmModules,
|
||||
RuntimeGlobals.esmRuntime
|
||||
],
|
||||
"data"
|
||||
),
|
||||
'// add "modules" to the modules object,',
|
||||
'// then flag all "ids" as loaded and fire callback',
|
||||
"var moduleId, chunkId, i = 0;",
|
||||
`for(moduleId in ${RuntimeGlobals.esmModules}) {`,
|
||||
Template.indent([
|
||||
`if(${RuntimeGlobals.hasOwnProperty}(${RuntimeGlobals.esmModules}, moduleId)) {`,
|
||||
Template.indent(
|
||||
`${RuntimeGlobals.moduleFactories}[moduleId] = ${RuntimeGlobals.esmModules}[moduleId];`
|
||||
),
|
||||
"}"
|
||||
]),
|
||||
"}",
|
||||
`if(${RuntimeGlobals.esmRuntime}) ${RuntimeGlobals.esmRuntime}(${RuntimeGlobals.require});`,
|
||||
`for(;i < ${RuntimeGlobals.esmIds}.length; i++) {`,
|
||||
Template.indent([
|
||||
`chunkId = ${RuntimeGlobals.esmIds}[i];`,
|
||||
`if(${RuntimeGlobals.hasOwnProperty}(installedChunks, chunkId) && installedChunks[chunkId]) {`,
|
||||
Template.indent("installedChunks[chunkId][0]();"),
|
||||
"}",
|
||||
`installedChunks[${RuntimeGlobals.esmIds}[i]] = 0;`
|
||||
]),
|
||||
"}",
|
||||
withOnChunkLoad ? `${RuntimeGlobals.onChunksLoaded}();` : ""
|
||||
])}`
|
||||
: "// no install chunk",
|
||||
"",
|
||||
withLoading
|
||||
? Template.asString([
|
||||
`${fn}.j = ${runtimeTemplate.basicFunction(
|
||||
"chunkId, promises",
|
||||
hasJsMatcher !== false
|
||||
? Template.indent([
|
||||
"// import() chunk loading for javascript",
|
||||
`var installedChunkData = ${RuntimeGlobals.hasOwnProperty}(installedChunks, chunkId) ? installedChunks[chunkId] : undefined;`,
|
||||
'if(installedChunkData !== 0) { // 0 means "already installed".',
|
||||
Template.indent([
|
||||
"",
|
||||
'// a Promise means "currently loading".',
|
||||
"if(installedChunkData) {",
|
||||
Template.indent([
|
||||
"promises.push(installedChunkData[1]);"
|
||||
]),
|
||||
"} else {",
|
||||
Template.indent([
|
||||
hasJsMatcher === true
|
||||
? "if(true) { // all chunks have JS"
|
||||
: `if(${hasJsMatcher("chunkId")}) {`,
|
||||
Template.indent([
|
||||
"// setup Promise in chunk cache",
|
||||
`var promise = ${importFunctionName}(${
|
||||
compilation.outputOptions.publicPath === "auto"
|
||||
? JSON.stringify(rootOutputDir)
|
||||
: RuntimeGlobals.publicPath
|
||||
} + ${
|
||||
RuntimeGlobals.getChunkScriptFilename
|
||||
}(chunkId)).then(installChunk, ${runtimeTemplate.basicFunction(
|
||||
"e",
|
||||
[
|
||||
"if(installedChunks[chunkId] !== 0) installedChunks[chunkId] = undefined;",
|
||||
"throw e;"
|
||||
]
|
||||
)});`,
|
||||
`var promise = Promise.race([promise, new Promise(${runtimeTemplate.expressionFunction(
|
||||
"installedChunkData = installedChunks[chunkId] = [resolve]",
|
||||
"resolve"
|
||||
)})])`,
|
||||
"promises.push(installedChunkData[1] = promise);"
|
||||
]),
|
||||
hasJsMatcher === true
|
||||
? "}"
|
||||
: "} else installedChunks[chunkId] = 0;"
|
||||
]),
|
||||
"}"
|
||||
]),
|
||||
"}"
|
||||
])
|
||||
: Template.indent(["installedChunks[chunkId] = 0;"])
|
||||
)};`
|
||||
])
|
||||
: "// no chunk on demand loading",
|
||||
"",
|
||||
withPrefetch && hasJsMatcher !== false
|
||||
? `${
|
||||
RuntimeGlobals.prefetchChunkHandlers
|
||||
}.j = ${runtimeTemplate.basicFunction("chunkId", [
|
||||
isNeutralPlatform
|
||||
? "if (typeof document === 'undefined') return;"
|
||||
: "",
|
||||
`if((!${
|
||||
RuntimeGlobals.hasOwnProperty
|
||||
}(installedChunks, chunkId) || installedChunks[chunkId] === undefined) && ${
|
||||
hasJsMatcher === true ? "true" : hasJsMatcher("chunkId")
|
||||
}) {`,
|
||||
Template.indent([
|
||||
"installedChunks[chunkId] = null;",
|
||||
linkPrefetch.call(
|
||||
Template.asString([
|
||||
"var link = document.createElement('link');",
|
||||
charset ? "link.charset = 'utf-8';" : "",
|
||||
crossOriginLoading
|
||||
? `link.crossOrigin = ${JSON.stringify(
|
||||
crossOriginLoading
|
||||
)};`
|
||||
: "",
|
||||
`if (${RuntimeGlobals.scriptNonce}) {`,
|
||||
Template.indent(
|
||||
`link.setAttribute("nonce", ${RuntimeGlobals.scriptNonce});`
|
||||
),
|
||||
"}",
|
||||
'link.rel = "prefetch";',
|
||||
'link.as = "script";',
|
||||
`link.href = ${RuntimeGlobals.publicPath} + ${RuntimeGlobals.getChunkScriptFilename}(chunkId);`
|
||||
]),
|
||||
chunk
|
||||
),
|
||||
"document.head.appendChild(link);"
|
||||
]),
|
||||
"}"
|
||||
])};`
|
||||
: "// no prefetching",
|
||||
"",
|
||||
withPreload && hasJsMatcher !== false
|
||||
? `${
|
||||
RuntimeGlobals.preloadChunkHandlers
|
||||
}.j = ${runtimeTemplate.basicFunction("chunkId", [
|
||||
isNeutralPlatform
|
||||
? "if (typeof document === 'undefined') return;"
|
||||
: "",
|
||||
`if((!${
|
||||
RuntimeGlobals.hasOwnProperty
|
||||
}(installedChunks, chunkId) || installedChunks[chunkId] === undefined) && ${
|
||||
hasJsMatcher === true ? "true" : hasJsMatcher("chunkId")
|
||||
}) {`,
|
||||
Template.indent([
|
||||
"installedChunks[chunkId] = null;",
|
||||
linkPreload.call(
|
||||
Template.asString([
|
||||
"var link = document.createElement('link');",
|
||||
charset ? "link.charset = 'utf-8';" : "",
|
||||
`if (${RuntimeGlobals.scriptNonce}) {`,
|
||||
Template.indent(
|
||||
`link.setAttribute("nonce", ${RuntimeGlobals.scriptNonce});`
|
||||
),
|
||||
"}",
|
||||
'link.rel = "modulepreload";',
|
||||
`link.href = ${RuntimeGlobals.publicPath} + ${RuntimeGlobals.getChunkScriptFilename}(chunkId);`,
|
||||
crossOriginLoading
|
||||
? crossOriginLoading === "use-credentials"
|
||||
? 'link.crossOrigin = "use-credentials";'
|
||||
: Template.asString([
|
||||
"if (link.href.indexOf(window.location.origin + '/') !== 0) {",
|
||||
Template.indent(
|
||||
`link.crossOrigin = ${JSON.stringify(
|
||||
crossOriginLoading
|
||||
)};`
|
||||
),
|
||||
"}"
|
||||
])
|
||||
: ""
|
||||
]),
|
||||
chunk
|
||||
),
|
||||
"document.head.appendChild(link);"
|
||||
]),
|
||||
"}"
|
||||
])};`
|
||||
: "// no preloaded",
|
||||
"",
|
||||
withExternalInstallChunk
|
||||
? Template.asString([
|
||||
`${RuntimeGlobals.externalInstallChunk} = installChunk;`
|
||||
])
|
||||
: "// no external install chunk",
|
||||
"",
|
||||
withOnChunkLoad
|
||||
? `${
|
||||
RuntimeGlobals.onChunksLoaded
|
||||
}.j = ${runtimeTemplate.returningFunction(
|
||||
"installedChunks[chunkId] === 0",
|
||||
"chunkId"
|
||||
)};`
|
||||
: "// no on chunks loaded",
|
||||
withHmr
|
||||
? Template.asString([
|
||||
generateJavascriptHMR("module"),
|
||||
"",
|
||||
"function loadUpdateChunk(chunkId, updatedModulesList) {",
|
||||
Template.indent([
|
||||
`return new Promise(${runtimeTemplate.basicFunction(
|
||||
"resolve, reject",
|
||||
[
|
||||
"// start update chunk loading",
|
||||
`var url = ${RuntimeGlobals.publicPath} + ${RuntimeGlobals.getChunkUpdateScriptFilename}(chunkId);`,
|
||||
`var onResolve = ${runtimeTemplate.basicFunction("obj", [
|
||||
`var updatedModules = obj.${RuntimeGlobals.esmModules};`,
|
||||
`var updatedRuntime = obj.${RuntimeGlobals.esmRuntime};`,
|
||||
"if(updatedRuntime) currentUpdateRuntime.push(updatedRuntime);",
|
||||
"for(var moduleId in updatedModules) {",
|
||||
Template.indent([
|
||||
`if(${RuntimeGlobals.hasOwnProperty}(updatedModules, moduleId)) {`,
|
||||
Template.indent([
|
||||
"currentUpdate[moduleId] = updatedModules[moduleId];",
|
||||
"if(updatedModulesList) updatedModulesList.push(moduleId);"
|
||||
]),
|
||||
"}"
|
||||
]),
|
||||
"}",
|
||||
"resolve(obj);"
|
||||
])};`,
|
||||
`var onReject = ${runtimeTemplate.basicFunction("error", [
|
||||
"var errorMsg = error.message || 'unknown reason';",
|
||||
"error.message = 'Loading hot update chunk ' + chunkId + ' failed.\\n(' + errorMsg + ')';",
|
||||
"error.name = 'ChunkLoadError';",
|
||||
"reject(error);"
|
||||
])}`,
|
||||
`var loadScript = ${runtimeTemplate.basicFunction(
|
||||
"url, onResolve, onReject",
|
||||
[
|
||||
`return ${importFunctionName}(/* webpackIgnore: true */ url).then(onResolve).catch(onReject)`
|
||||
]
|
||||
)}`,
|
||||
"loadScript(url, onResolve, onReject);"
|
||||
]
|
||||
)});`
|
||||
]),
|
||||
"}",
|
||||
""
|
||||
])
|
||||
: "// no HMR",
|
||||
"",
|
||||
withHmrManifest
|
||||
? Template.asString([
|
||||
`${
|
||||
RuntimeGlobals.hmrDownloadManifest
|
||||
} = ${runtimeTemplate.basicFunction("", [
|
||||
`return ${importFunctionName}(/* webpackIgnore: true */ ${RuntimeGlobals.publicPath} + ${
|
||||
RuntimeGlobals.getUpdateManifestFilename
|
||||
}()).then(${runtimeTemplate.basicFunction("obj", [
|
||||
"return obj.default;"
|
||||
])}, ${runtimeTemplate.basicFunction("error", [
|
||||
"if(['MODULE_NOT_FOUND', 'ENOENT'].includes(error.code)) return;",
|
||||
"throw error;"
|
||||
])});`
|
||||
])};`
|
||||
])
|
||||
: "// no HMR manifest"
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ModuleChunkLoadingRuntimeModule;
|
||||
Reference in New Issue
Block a user