EvalSourceMapDevToolPlugin.js 976B

123456789101112131415161718192021222324252627282930313233
  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("EvalSourceMapDevToolPlugin only takes one argument (pass an options object)");
  12. if(typeof options === "string") {
  13. options = {
  14. append: options
  15. };
  16. }
  17. if(!options) options = {};
  18. this.options = options;
  19. }
  20. apply(compiler) {
  21. const options = this.options;
  22. compiler.plugin("compilation", (compilation) => {
  23. new SourceMapDevToolModuleOptionsPlugin(options).apply(compilation);
  24. compilation.moduleTemplate.apply(new EvalSourceMapDevToolModuleTemplatePlugin(compilation, options));
  25. });
  26. }
  27. }
  28. module.exports = EvalSourceMapDevToolPlugin;