SourceMapDevToolModuleOptionsPlugin.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  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.plugin("build-module", module => {
  15. module.useSourceMap = true;
  16. });
  17. }
  18. if(options.lineToLine === true) {
  19. compilation.plugin("build-module", module => {
  20. module.lineToLine = true;
  21. });
  22. } else if(options.lineToLine) {
  23. compilation.plugin("build-module", module => {
  24. if(!module.resource) return;
  25. let resourcePath = module.resource;
  26. const idx = resourcePath.indexOf("?");
  27. if(idx >= 0) resourcePath = resourcePath.substr(0, idx);
  28. module.lineToLine = ModuleFilenameHelpers.matchObject(options.lineToLine, resourcePath);
  29. });
  30. }
  31. }
  32. }
  33. module.exports = SourceMapDevToolModuleOptionsPlugin;