/
githubmirror
/
webpack
Обзор
Документация
Войти
/
githubmirror
/
webpack
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
lib/node/NodeTargetPlugin.js
43 строки
1 KB
Alexander Akait
Respect the node: prefix for node.js core modules used as externals (#21286)
26 июн 2026, 18:55
Не верифицирован
26 июн 2026, 18:55
54fa902
Код
Авторство
О чём код?
/* MIT License http://www.opensource.org/licenses/mit-license.php Author Tobias Koppers @sokra */ "use strict"; const ExternalsPlugin = require("../ExternalsPlugin"); const { builtins } = require("./nodeBuiltins"); /** @typedef {import("../../declarations/WebpackOptions").ExternalsType} ExternalsType */ /** @typedef {import("../Compiler")} Compiler */ class NodeTargetPlugin { /** * Creates an instance of NodeTargetPlugin. * @param {ExternalsType} type default external type */ constructor(type = "node-commonjs") { /** @type {ExternalsType} */ this.type = type; } /** * Applies the plugin by registering its hooks on the compiler. * @param {Compiler} compiler the compiler instance * @returns {void} */ apply(compiler) { new ExternalsPlugin((dependency) => { // When `require` node.js built-in modules with module output // we should still emit `createRequire` for compatibility if (dependency.category === "commonjs") { return "node-commonjs"; } return this.type; }, builtins).apply(compiler); } } module.exports = NodeTargetPlugin; module.exports.builtins = builtins;