LoaderTargetPlugin.js 885 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. /** @import Compiler from "./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. /** @type {string} */
  16. this.target = target;
  17. }
  18. /**
  19. * Applies the plugin by registering its hooks on the compiler.
  20. * @param {Compiler} compiler the compiler instance
  21. * @returns {void}
  22. */
  23. apply(compiler) {
  24. compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
  25. NormalModule.getCompilationHooks(compilation).loader.tap(
  26. PLUGIN_NAME,
  27. (loaderContext) => {
  28. loaderContext.target = this.target;
  29. }
  30. );
  31. });
  32. }
  33. }
  34. module.exports = LoaderTargetPlugin;