webpack/lib/DelegatedPlugin.js

44 lines
1015 B
JavaScript
Raw Normal View History

2015-05-13 06:17:06 +08:00
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
"use strict";
const DelegatedModuleFactoryPlugin = require("./DelegatedModuleFactoryPlugin");
2018-07-30 23:08:51 +08:00
const DelegatedSourceDependency = require("./dependencies/DelegatedSourceDependency");
2018-11-03 04:05:46 +08:00
/** @typedef {import("./Compiler")} Compiler */
class DelegatedPlugin {
constructor(options) {
this.options = options;
}
2018-11-03 04:05:46 +08:00
/**
* Apply the plugin
* @param {Compiler} compiler the compiler instance
* @returns {void}
*/
apply(compiler) {
2018-02-25 09:00:20 +08:00
compiler.hooks.compilation.tap(
"DelegatedPlugin",
(compilation, { normalModuleFactory }) => {
compilation.dependencyFactories.set(
DelegatedSourceDependency,
normalModuleFactory
);
}
);
2018-02-25 09:00:20 +08:00
compiler.hooks.compile.tap("DelegatedPlugin", ({ normalModuleFactory }) => {
new DelegatedModuleFactoryPlugin({
associatedObjectForCache: compiler.root,
...this.options
}).apply(normalModuleFactory);
});
}
2015-05-13 06:17:06 +08:00
}
module.exports = DelegatedPlugin;