SourceMapDevToolModuleOptionsPlugin.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const JavascriptModulesPlugin = require("./javascript/JavascriptModulesPlugin");
  7. /** @typedef {import("./Compilation")} Compilation */
  8. class SourceMapDevToolModuleOptionsPlugin {
  9. constructor(options) {
  10. this.options = options;
  11. }
  12. /**
  13. * @param {Compilation} compilation the compiler instance
  14. * @returns {void}
  15. */
  16. apply(compilation) {
  17. const options = this.options;
  18. if (options.module !== false) {
  19. compilation.hooks.buildModule.tap(
  20. "SourceMapDevToolModuleOptionsPlugin",
  21. module => {
  22. module.useSourceMap = true;
  23. }
  24. );
  25. compilation.hooks.runtimeModule.tap(
  26. "SourceMapDevToolModuleOptionsPlugin",
  27. module => {
  28. module.useSourceMap = true;
  29. }
  30. );
  31. } else {
  32. compilation.hooks.buildModule.tap(
  33. "SourceMapDevToolModuleOptionsPlugin",
  34. module => {
  35. module.useSimpleSourceMap = true;
  36. }
  37. );
  38. compilation.hooks.runtimeModule.tap(
  39. "SourceMapDevToolModuleOptionsPlugin",
  40. module => {
  41. module.useSimpleSourceMap = true;
  42. }
  43. );
  44. }
  45. JavascriptModulesPlugin.getCompilationHooks(compilation).useSourceMap.tap(
  46. "SourceMapDevToolModuleOptionsPlugin",
  47. () => true
  48. );
  49. }
  50. }
  51. module.exports = SourceMapDevToolModuleOptionsPlugin;