SourceMapDevToolModuleOptionsPlugin.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const ModuleFilenameHelpers = require("./ModuleFilenameHelpers");
  7. class SourceMapDevToolModuleOptionsPlugin {
  8. constructor(options) {
  9. this.options = options;
  10. }
  11. apply(compilation) {
  12. const options = this.options;
  13. if (options.module !== false) {
  14. compilation.hooks.buildModule.tap(
  15. "SourceMapDevToolModuleOptionsPlugin",
  16. module => {
  17. module.useSourceMap = true;
  18. }
  19. );
  20. }
  21. if (options.lineToLine === true) {
  22. compilation.hooks.buildModule.tap(
  23. "SourceMapDevToolModuleOptionsPlugin",
  24. module => {
  25. module.lineToLine = true;
  26. }
  27. );
  28. } else if (options.lineToLine) {
  29. compilation.hooks.buildModule.tap(
  30. "SourceMapDevToolModuleOptionsPlugin",
  31. module => {
  32. if (!module.resource) return;
  33. let resourcePath = module.resource;
  34. const idx = resourcePath.indexOf("?");
  35. if (idx >= 0) resourcePath = resourcePath.substr(0, idx);
  36. module.lineToLine = ModuleFilenameHelpers.matchObject(
  37. options.lineToLine,
  38. resourcePath
  39. );
  40. }
  41. );
  42. }
  43. }
  44. }
  45. module.exports = SourceMapDevToolModuleOptionsPlugin;