webpack/lib/LoaderTargetPlugin.js

38 lines
747 B
JavaScript
Raw Permalink Normal View History

/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
2018-07-30 23:08:51 +08:00
"use strict";
2018-11-12 21:13:55 +08:00
const NormalModule = require("./NormalModule");
2018-11-09 05:59:19 +08:00
/** @typedef {import("./Compiler")} Compiler */
class LoaderTargetPlugin {
2018-11-09 05:59:19 +08:00
/**
* @param {string} target the target
*/
constructor(target) {
this.target = target;
}
2018-11-09 05:59:19 +08:00
/**
2020-04-23 16:48:36 +08:00
* Apply the plugin
2018-11-09 05:59:19 +08:00
* @param {Compiler} compiler the compiler instance
* @returns {void}
*/
apply(compiler) {
2018-02-25 09:00:20 +08:00
compiler.hooks.compilation.tap("LoaderTargetPlugin", compilation => {
2018-11-12 21:13:55 +08:00
NormalModule.getCompilationHooks(compilation).loader.tap(
2018-02-25 09:00:20 +08:00
"LoaderTargetPlugin",
loaderContext => {
loaderContext.target = this.target;
}
);
});
}
}
module.exports = LoaderTargetPlugin;