Skip to content

Commit 3ec9407

Browse files
committed
refactor(es6): Upgrade lib/webpack.js to es6
1 parent 9c2eae9 commit 3ec9407

1 file changed

Lines changed: 18 additions & 21 deletions

File tree

lib/webpack.js

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,25 @@
22
MIT License http://www.opensource.org/licenses/mit-license.php
33
Author Tobias Koppers @sokra
44
*/
5-
var Compiler = require("./Compiler");
6-
var MultiCompiler = require("./MultiCompiler");
7-
var NodeEnvironmentPlugin = require("./node/NodeEnvironmentPlugin");
8-
var WebpackOptionsApply = require("./WebpackOptionsApply");
9-
var WebpackOptionsDefaulter = require("./WebpackOptionsDefaulter");
10-
var validateSchema = require("./validateSchema");
11-
var WebpackOptionsValidationError = require("./WebpackOptionsValidationError");
12-
var webpackOptionsSchema = require("../schemas/webpackOptionsSchema.json");
5+
"use strict";
6+
7+
const Compiler = require("./Compiler");
8+
const MultiCompiler = require("./MultiCompiler");
9+
const NodeEnvironmentPlugin = require("./node/NodeEnvironmentPlugin");
10+
const WebpackOptionsApply = require("./WebpackOptionsApply");
11+
const WebpackOptionsDefaulter = require("./WebpackOptionsDefaulter");
12+
const validateSchema = require("./validateSchema");
13+
const WebpackOptionsValidationError = require("./WebpackOptionsValidationError");
14+
const webpackOptionsSchema = require("../schemas/webpackOptionsSchema.json");
1315

1416
function webpack(options, callback) {
15-
var webpackOptionsValidationErrors = validateSchema(webpackOptionsSchema, options);
17+
const webpackOptionsValidationErrors = validateSchema(webpackOptionsSchema, options);
1618
if(webpackOptionsValidationErrors.length) {
1719
throw new WebpackOptionsValidationError(webpackOptionsValidationErrors);
1820
}
19-
var compiler;
21+
let compiler;
2022
if(Array.isArray(options)) {
21-
compiler = new MultiCompiler(options.map(function(options) {
22-
return webpack(options);
23-
}));
23+
compiler = new MultiCompiler(options.map(options => webpack(options)));
2424
} else if(typeof options === "object") {
2525
new WebpackOptionsDefaulter().process(options);
2626

@@ -39,11 +39,8 @@ function webpack(options, callback) {
3939
}
4040
if(callback) {
4141
if(typeof callback !== "function") throw new Error("Invalid argument: callback");
42-
if(options.watch === true || (Array.isArray(options) &&
43-
options.some(function(o) {
44-
return o.watch;
45-
}))) {
46-
var watchOptions = (!Array.isArray(options) ? options : options[0]).watchOptions || {};
42+
if(options.watch === true || (Array.isArray(options) && options.some(o => o.watch))) {
43+
const watchOptions = (!Array.isArray(options) ? options : options[0]).watchOptions || {};
4744
return compiler.watch(watchOptions, callback);
4845
}
4946
compiler.run(callback);
@@ -62,12 +59,12 @@ webpack.validateSchema = validateSchema;
6259
webpack.WebpackOptionsValidationError = WebpackOptionsValidationError;
6360

6461
function exportPlugins(exports, path, plugins) {
65-
plugins.forEach(function(name) {
62+
plugins.forEach(name => {
6663
Object.defineProperty(exports, name, {
6764
configurable: false,
6865
enumerable: true,
69-
get: function() {
70-
return require(path + "/" + name);
66+
get() {
67+
return require(`${path}/${name}`)
7168
}
7269
});
7370
});

0 commit comments

Comments
 (0)