Merge pull request #3667 from chicoxyzzy/feature/refactor_es6_webpack

refactor(es6): Upgrade lib/webpack.js to es6
This commit is contained in:
Tobias Koppers 2017-01-02 09:12:11 +01:00 committed by GitHub
commit 09b90c1b8a
1 changed files with 18 additions and 21 deletions

View File

@ -2,25 +2,25 @@
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
var Compiler = require("./Compiler");
var MultiCompiler = require("./MultiCompiler");
var NodeEnvironmentPlugin = require("./node/NodeEnvironmentPlugin");
var WebpackOptionsApply = require("./WebpackOptionsApply");
var WebpackOptionsDefaulter = require("./WebpackOptionsDefaulter");
var validateSchema = require("./validateSchema");
var WebpackOptionsValidationError = require("./WebpackOptionsValidationError");
var webpackOptionsSchema = require("../schemas/webpackOptionsSchema.json");
"use strict";
const Compiler = require("./Compiler");
const MultiCompiler = require("./MultiCompiler");
const NodeEnvironmentPlugin = require("./node/NodeEnvironmentPlugin");
const WebpackOptionsApply = require("./WebpackOptionsApply");
const WebpackOptionsDefaulter = require("./WebpackOptionsDefaulter");
const validateSchema = require("./validateSchema");
const WebpackOptionsValidationError = require("./WebpackOptionsValidationError");
const webpackOptionsSchema = require("../schemas/webpackOptionsSchema.json");
function webpack(options, callback) {
var webpackOptionsValidationErrors = validateSchema(webpackOptionsSchema, options);
const webpackOptionsValidationErrors = validateSchema(webpackOptionsSchema, options);
if(webpackOptionsValidationErrors.length) {
throw new WebpackOptionsValidationError(webpackOptionsValidationErrors);
}
var compiler;
let compiler;
if(Array.isArray(options)) {
compiler = new MultiCompiler(options.map(function(options) {
return webpack(options);
}));
compiler = new MultiCompiler(options.map(options => webpack(options)));
} else if(typeof options === "object") {
new WebpackOptionsDefaulter().process(options);
@ -39,11 +39,8 @@ function webpack(options, callback) {
}
if(callback) {
if(typeof callback !== "function") throw new Error("Invalid argument: callback");
if(options.watch === true || (Array.isArray(options) &&
options.some(function(o) {
return o.watch;
}))) {
var watchOptions = (!Array.isArray(options) ? options : options[0]).watchOptions || {};
if(options.watch === true || (Array.isArray(options) && options.some(o => o.watch))) {
const watchOptions = (!Array.isArray(options) ? options : options[0]).watchOptions || {};
return compiler.watch(watchOptions, callback);
}
compiler.run(callback);
@ -62,12 +59,12 @@ webpack.validateSchema = validateSchema;
webpack.WebpackOptionsValidationError = WebpackOptionsValidationError;
function exportPlugins(exports, path, plugins) {
plugins.forEach(function(name) {
plugins.forEach(name => {
Object.defineProperty(exports, name, {
configurable: false,
enumerable: true,
get: function() {
return require(path + "/" + name);
get() {
return require(`${path}/${name}`)
}
});
});