LoaderTargetPlugin.js 747 B

12345678910111213141516171819202122232425262728293031323334353637
  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. class LoaderTargetPlugin {
  9. /**
  10. * @param {string} target the target
  11. */
  12. constructor(target) {
  13. this.target = target;
  14. }
  15. /**
  16. * Apply the plugin
  17. * @param {Compiler} compiler the compiler instance
  18. * @returns {void}
  19. */
  20. apply(compiler) {
  21. compiler.hooks.compilation.tap("LoaderTargetPlugin", compilation => {
  22. NormalModule.getCompilationHooks(compilation).loader.tap(
  23. "LoaderTargetPlugin",
  24. loaderContext => {
  25. loaderContext.target = this.target;
  26. }
  27. );
  28. });
  29. }
  30. }
  31. module.exports = LoaderTargetPlugin;