SourceMapDevToolModuleOptionsPlugin.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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("../declarations/plugins/SourceMapDevToolPlugin").SourceMapDevToolPluginOptions} SourceMapDevToolPluginOptions */
  8. /** @typedef {import("./Compilation")} Compilation */
  9. class SourceMapDevToolModuleOptionsPlugin {
  10. /**
  11. * @param {SourceMapDevToolPluginOptions} options options
  12. */
  13. constructor(options) {
  14. this.options = options;
  15. }
  16. /**
  17. * @param {Compilation} compilation the compiler instance
  18. * @returns {void}
  19. */
  20. apply(compilation) {
  21. const options = this.options;
  22. if (options.module !== false) {
  23. compilation.hooks.buildModule.tap(
  24. "SourceMapDevToolModuleOptionsPlugin",
  25. module => {
  26. module.useSourceMap = true;
  27. }
  28. );
  29. compilation.hooks.runtimeModule.tap(
  30. "SourceMapDevToolModuleOptionsPlugin",
  31. module => {
  32. module.useSourceMap = true;
  33. }
  34. );
  35. } else {
  36. compilation.hooks.buildModule.tap(
  37. "SourceMapDevToolModuleOptionsPlugin",
  38. module => {
  39. module.useSimpleSourceMap = true;
  40. }
  41. );
  42. compilation.hooks.runtimeModule.tap(
  43. "SourceMapDevToolModuleOptionsPlugin",
  44. module => {
  45. module.useSimpleSourceMap = true;
  46. }
  47. );
  48. }
  49. JavascriptModulesPlugin.getCompilationHooks(compilation).useSourceMap.tap(
  50. "SourceMapDevToolModuleOptionsPlugin",
  51. () => true
  52. );
  53. }
  54. }
  55. module.exports = SourceMapDevToolModuleOptionsPlugin;