mirror of https://github.com/webpack/webpack.git
Merge pull request #3942 from carloscuatin/refactor-eval-source-map-dev-tool-plugin
refactor(es6) upgrade EvalSourceMapDevToolPlugin to ES6 class
This commit is contained in:
commit
c4be4564af
|
|
@ -2,25 +2,31 @@
|
|||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
var EvalSourceMapDevToolModuleTemplatePlugin = require("./EvalSourceMapDevToolModuleTemplatePlugin");
|
||||
var SourceMapDevToolModuleOptionsPlugin = require("./SourceMapDevToolModuleOptionsPlugin");
|
||||
"use strict";
|
||||
|
||||
function EvalSourceMapDevToolPlugin(options) {
|
||||
if(arguments.length > 1)
|
||||
throw new Error("EvalSourceMapDevToolPlugin only takes one argument (pass an options object)");
|
||||
if(typeof options === "string") {
|
||||
options = {
|
||||
append: options
|
||||
};
|
||||
const EvalSourceMapDevToolModuleTemplatePlugin = require("./EvalSourceMapDevToolModuleTemplatePlugin");
|
||||
const SourceMapDevToolModuleOptionsPlugin = require("./SourceMapDevToolModuleOptionsPlugin");
|
||||
|
||||
class EvalSourceMapDevToolPlugin {
|
||||
constructor(options) {
|
||||
if(arguments.length > 1)
|
||||
throw new Error("EvalSourceMapDevToolPlugin only takes one argument (pass an options object)");
|
||||
if(typeof options === "string") {
|
||||
options = {
|
||||
append: options
|
||||
};
|
||||
}
|
||||
if(!options) options = {};
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
apply(compiler) {
|
||||
let options = this.options;
|
||||
compiler.plugin("compilation", (compilation) => {
|
||||
new SourceMapDevToolModuleOptionsPlugin(options).apply(compilation);
|
||||
compilation.moduleTemplate.apply(new EvalSourceMapDevToolModuleTemplatePlugin(compilation, options));
|
||||
});
|
||||
}
|
||||
if(!options) options = {};
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
module.exports = EvalSourceMapDevToolPlugin;
|
||||
EvalSourceMapDevToolPlugin.prototype.apply = function(compiler) {
|
||||
var options = this.options;
|
||||
compiler.plugin("compilation", function(compilation) {
|
||||
new SourceMapDevToolModuleOptionsPlugin(options).apply(compilation);
|
||||
compilation.moduleTemplate.apply(new EvalSourceMapDevToolModuleTemplatePlugin(compilation, options));
|
||||
});
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue