LoaderTargetPlugin.js 867 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const NormalModule = require("./NormalModule");
  7. /** @typedef {import("./Compiler")} Compiler */
  8. const PLUGIN_NAME = "LoaderTargetPlugin";
  9. class LoaderTargetPlugin {
  10. /**
  11. * Creates an instance of LoaderTargetPlugin.
  12. * @param {string} target the target
  13. */
  14. constructor(target) {
  15. this.target = target;
  16. }
  17. /**
  18. * Applies the plugin by registering its hooks on the compiler.
  19. * @param {Compiler} compiler the compiler instance
  20. * @returns {void}
  21. */
  22. apply(compiler) {
  23. compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
  24. NormalModule.getCompilationHooks(compilation).loader.tap(
  25. PLUGIN_NAME,
  26. (loaderContext) => {
  27. loaderContext.target = this.target;
  28. }
  29. );
  30. });
  31. }
  32. }
  33. module.exports = LoaderTargetPlugin;