Files
dewedev/node_modules/webpack/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js
dwindown 7f2dd5260f Initial commit: Developer Tools MVP with visual editor
- Complete React app with 7 developer tools
- JSON Tool with visual structured editor
- Serialize Tool with visual structured editor
- URL, Base64, CSV/JSON, Beautifier, Diff tools
- Responsive navigation with dropdown menu
- Dark/light mode toggle
- Mobile-responsive design with sticky header
- All tools working with copy/paste functionality
2025-08-02 09:31:26 +07:00

46 lines
1.3 KiB
JavaScript

/*
MIT License http://www.opensource.org/licenses/mit-license.php
*/
"use strict";
const RuntimeGlobals = require("../RuntimeGlobals");
const RuntimeModule = require("../RuntimeModule");
const Template = require("../Template");
/** @typedef {import("../Compilation")} Compilation */
/** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
class ChunkPreloadTriggerRuntimeModule extends RuntimeModule {
/**
* @param {Record<string|number, (string|number)[]>} chunkMap map from chunk to chunks
*/
constructor(chunkMap) {
super("chunk preload trigger", RuntimeModule.STAGE_TRIGGER);
this.chunkMap = chunkMap;
}
/**
* @returns {string | null} runtime code
*/
generate() {
const { chunkMap } = this;
const compilation = /** @type {Compilation} */ (this.compilation);
const { runtimeTemplate } = compilation;
const body = [
"var chunks = chunkToChildrenMap[chunkId];",
`Array.isArray(chunks) && chunks.map(${RuntimeGlobals.preloadChunk});`
];
return Template.asString([
Template.asString([
`var chunkToChildrenMap = ${JSON.stringify(chunkMap, null, "\t")};`,
`${
RuntimeGlobals.ensureChunkHandlers
}.preload = ${runtimeTemplate.basicFunction("chunkId", body)};`
])
]);
}
}
module.exports = ChunkPreloadTriggerRuntimeModule;