UNPKG

899 BJavaScriptView Raw
1/*
2 MIT License http://www.opensource.org/licenses/mit-license.php
3 Author Tobias Koppers @sokra
4*/
5
6"use strict";
7
8const ExternalModuleFactoryPlugin = require("./ExternalModuleFactoryPlugin");
9
10/** @typedef {import("../declarations/WebpackOptions").Externals} Externals */
11/** @typedef {import("./Compiler")} Compiler */
12
13class ExternalsPlugin {
14 /**
15 * @param {string | undefined} type default external type
16 * @param {Externals} externals externals config
17 */
18 constructor(type, externals) {
19 this.type = type;
20 this.externals = externals;
21 }
22
23 /**
24 * Apply the plugin
25 * @param {Compiler} compiler the compiler instance
26 * @returns {void}
27 */
28 apply(compiler) {
29 compiler.hooks.compile.tap("ExternalsPlugin", ({ normalModuleFactory }) => {
30 new ExternalModuleFactoryPlugin(this.type, this.externals).apply(
31 normalModuleFactory
32 );
33 });
34 }
35}
36
37module.exports = ExternalsPlugin;