webpack/lib/ExternalsPlugin.js

40 lines
933 B
JavaScript
Raw Normal View History

2014-03-05 16:58:51 +08:00
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
2018-07-30 23:08:51 +08:00
"use strict";
2017-11-15 16:28:45 +08:00
const ExternalModuleFactoryPlugin = require("./ExternalModuleFactoryPlugin");
2014-03-05 16:58:51 +08:00
/** @typedef {import("../declarations/WebpackOptions").Externals} Externals */
2018-11-03 04:05:46 +08:00
/** @typedef {import("./Compiler")} Compiler */
2025-04-23 20:03:37 +08:00
const PLUGIN_NAME = "ExternalsPlugin";
class ExternalsPlugin {
/**
* @param {string | undefined} type default external type
* @param {Externals} externals externals config
*/
constructor(type, externals) {
this.type = type;
this.externals = externals;
}
2018-11-03 04:05:46 +08:00
/**
2020-04-23 16:48:36 +08:00
* Apply the plugin
2018-11-03 04:05:46 +08:00
* @param {Compiler} compiler the compiler instance
* @returns {void}
*/
apply(compiler) {
2025-04-23 20:03:37 +08:00
compiler.hooks.compile.tap(PLUGIN_NAME, ({ normalModuleFactory }) => {
new ExternalModuleFactoryPlugin(this.type, this.externals).apply(
normalModuleFactory
);
});
}
2014-03-05 16:58:51 +08:00
}
2014-03-05 16:58:51 +08:00
module.exports = ExternalsPlugin;