/
githubmirror
/
webpack
Обзор
Документация
Войти
/
githubmirror
/
webpack
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
v5.106.0
lib/optimize/RuntimeChunkPlugin.js
52 строки
1 KB
Alexander Akait
refactor: improve types coverage (#20402)
04 фев 2026, 15:32
Не верифицирован
04 фев 2026, 15:32
97decb4
Код
Авторство
О чём код?
/* MIT License http://www.opensource.org/licenses/mit-license.php Author Tobias Koppers @sokra */ "use strict"; /** @typedef {import("../Compilation").EntryData} EntryData */ /** @typedef {import("../Compiler")} Compiler */ const PLUGIN_NAME = "RuntimeChunkPlugin"; /** @typedef {(entrypoint: { name: string }) => string} RuntimeChunkFunction */ class RuntimeChunkPlugin { /** * @param {{ name?: RuntimeChunkFunction }=} options options */ constructor(options = {}) { /** @type {{ name: string | RuntimeChunkFunction }} */ this.options = { name: (entrypoint) => `runtime~${entrypoint.name}`, ...options }; } /** * Apply the plugin * @param {Compiler} compiler the compiler instance * @returns {void} */ apply(compiler) { compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => { compilation.hooks.addEntry.tap(PLUGIN_NAME, (_, { name: entryName }) => { if (entryName === undefined) return; const data = /** @type {EntryData} */ (compilation.entries.get(entryName)); if (data.options.runtime === undefined && !data.options.dependOn) { // Determine runtime chunk name let name = this.options.name; if (typeof name === "function") { name = name({ name: entryName }); } data.options.runtime = name; } }); }); } } module.exports = RuntimeChunkPlugin;