LoaderTargetPlugin.js 772 B

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