EvalSourceMapDevToolPlugin.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const EvalSourceMapDevToolModuleTemplatePlugin = require("./EvalSourceMapDevToolModuleTemplatePlugin");
  7. const SourceMapDevToolModuleOptionsPlugin = require("./SourceMapDevToolModuleOptionsPlugin");
  8. class EvalSourceMapDevToolPlugin {
  9. constructor(options) {
  10. if (arguments.length > 1) {
  11. throw new Error(
  12. "EvalSourceMapDevToolPlugin only takes one argument (pass an options object)"
  13. );
  14. }
  15. if (typeof options === "string") {
  16. options = {
  17. append: options
  18. };
  19. }
  20. if (!options) options = {};
  21. this.options = options;
  22. }
  23. apply(compiler) {
  24. const options = this.options;
  25. compiler.hooks.compilation.tap(
  26. "EvalSourceMapDevToolPlugin",
  27. compilation => {
  28. new SourceMapDevToolModuleOptionsPlugin(options).apply(compilation);
  29. new EvalSourceMapDevToolModuleTemplatePlugin(
  30. compilation,
  31. options
  32. ).apply(compilation.moduleTemplates.javascript);
  33. }
  34. );
  35. }
  36. }
  37. module.exports = EvalSourceMapDevToolPlugin;