Skip to content

Commit 6cff63a

Browse files
committedOct 20, 2018
webpack, babel upgrade
1 parent 5d3c110 commit 6cff63a

File tree

5 files changed

+82
-71
lines changed

5 files changed

+82
-71
lines changed
 

‎.babelrc

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
{
2-
"presets":[
3-
"react",
4-
["es2015", {"loose": true}]
2+
"presets": [
3+
"@babel/preset-env",
4+
"@babel/preset-react"
55
],
66
"plugins": [
7-
"transform-object-assign",
8-
"transform-object-rest-spread",
9-
"transform-class-properties"
7+
"@babel/plugin-proposal-class-properties"
108
]
119
}

‎gulpfile.js

+13-6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ var WebpackDevServer = require("webpack-dev-server");
88
var assign = require("object-assign");
99
var opn = require("opn");
1010

11+
var UglifyJsPlugin = require("uglifyjs-webpack-plugin");
12+
1113
const DEV_PORT = 8080;
1214

1315
gulp.task("clean", function() {
@@ -54,7 +56,7 @@ gulp.task(
5456

5557
gulp.task(
5658
"server",
57-
gulp.series(["watch", "copy", "sass"], function(done) {
59+
gulp.series(["watch", "copy", "sass"], function() {
5860
console.log("Start");
5961
var myConfig = require("./webpack.config");
6062
myConfig.plugins = myConfig.plugins.concat(
@@ -68,8 +70,10 @@ gulp.task(
6870
new WebpackDevServer(webpack(myConfig), {
6971
contentBase: "./build",
7072
hot: true,
71-
debug: true
72-
}).listen(DEV_PORT, "0.0.0.0", function(err, result) {
73+
stats: {
74+
colors: true
75+
}
76+
}).listen(DEV_PORT, "localhost", function(err, result) {
7377
if (err) {
7478
console.log(err);
7579
} else {
@@ -78,7 +82,6 @@ gulp.task(
7882
opn(server_url);
7983
}
8084
});
81-
done();
8285
})
8386
);
8487

@@ -91,6 +94,7 @@ var distConfig = require("./webpack.config.dist.js");
9194
gulp.task("dist-unmin", function(cb) {
9295
var unminConfig = assign({}, distConfig);
9396
unminConfig.output.filename = "react-slick.js";
97+
unminConfig.mode = "none";
9498
return webpack(unminConfig, function(err, stat) {
9599
console.error(err);
96100
cb();
@@ -101,8 +105,11 @@ gulp.task("dist-min", function(cb) {
101105
var minConfig = assign({}, distConfig);
102106
minConfig.output.filename = "react-slick.min.js";
103107
minConfig.plugins = minConfig.plugins.concat(
104-
new webpack.optimize.UglifyJsPlugin({
105-
compressor: {
108+
new UglifyJsPlugin({
109+
cache: true,
110+
parallel: true,
111+
sourceMap: true,
112+
uglifyOptions: {
106113
warnings: false
107114
}
108115
})

‎package.json

+14-12
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,18 @@
3232
"react-component"
3333
],
3434
"devDependencies": {
35+
"@babel/cli": "^7.0.0",
36+
"@babel/core": "^7.1.2",
37+
"@babel/plugin-proposal-class-properties": "^7.1.0",
38+
"@babel/polyfill": "^7.0.0",
39+
"@babel/preset-env": "^7.1.0",
40+
"@babel/preset-react": "^7.0.0",
3541
"autoprefixer": "^7.1.2",
36-
"babel-cli": "^6.16.0",
37-
"babel-core": "^6.16.0",
38-
"babel-eslint": "^7.0.0",
39-
"babel-jest": "^19.0.0",
40-
"babel-loader": "^6.2.5",
41-
"babel-plugin-transform-class-properties": "^6.24.1",
42-
"babel-plugin-transform-object-assign": "^6.8.0",
43-
"babel-polyfill": "^6.16.0",
42+
"babel-core": "^7.0.0-bridge.0",
43+
"babel-eslint": "^9.0.0",
44+
"babel-jest": "^23.4.2",
45+
"babel-loader": "^8.0.4",
4446
"babel-preset-airbnb": "^2.1.1",
45-
"babel-preset-es2015": "^6.16.0",
46-
"babel-preset-react": "^6.16.0",
4747
"css-loader": "^0.28.0",
4848
"deepmerge": "^1.1.0",
4949
"del": "^2.2.2",
@@ -76,8 +76,10 @@
7676
"sinon": "^2.1.0",
7777
"slick-carousel": "^1.8.1",
7878
"style-loader": "^0.16.1",
79-
"webpack": "^1.13.2",
80-
"webpack-dev-server": "^1.16.1",
79+
"uglifyjs-webpack-plugin": "^2.0.1",
80+
"webpack": "^4.21.0",
81+
"webpack-cli": "^3.1.2",
82+
"webpack-dev-server": "^3.1.9",
8183
"why-did-you-update": "^0.1.1"
8284
},
8385
"dependencies": {

‎webpack.config.dist.js

+31-24
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ var webpack = require("webpack");
22
var path = require("path");
33

44
module.exports = {
5+
mode: "production",
6+
57
entry: "./src/index",
68

79
output: {
@@ -11,40 +13,45 @@ module.exports = {
1113
},
1214

1315
module: {
14-
loaders: [
15-
{ test: /\.jsx$/, loaders: ["babel"] },
16-
{ test: /\.js$/, loaders: ["babel"], exclude: /node_modules/ }
16+
rules: [
17+
{
18+
test: /\.js/,
19+
exclude: /(node_modules)/,
20+
use: {
21+
loader: "babel-loader"
22+
}
23+
}
1724
]
1825
},
1926

2027
resolve: {
21-
extensions: ["", ".js", ".jsx"]
28+
extensions: [".js", ".jsx"]
2229
},
2330

24-
externals: [
25-
{
26-
react: {
27-
root: "React",
28-
commonjs2: "react",
29-
commonjs: "react",
30-
amd: "react"
31-
},
32-
"react-dom": {
33-
root: "ReactDOM",
34-
commonjs2: "react-dom",
35-
commonjs: "react-dom",
36-
amd: "react-dom"
37-
}
31+
externals: {
32+
react: {
33+
root: "React",
34+
commonjs2: "react",
35+
commonjs: "react",
36+
amd: "react"
37+
},
38+
"react-dom": {
39+
root: "ReactDOM",
40+
commonjs2: "react-dom",
41+
commonjs: "react-dom",
42+
amd: "react-dom"
3843
}
39-
],
44+
},
4045

4146
node: {
4247
Buffer: false
4348
},
4449

45-
plugins: [
46-
new webpack.DefinePlugin({
47-
"process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV)
48-
})
49-
]
50+
devtool: "source-map",
51+
52+
performance: {
53+
hints: "warning"
54+
},
55+
56+
plugins: []
5057
};

‎webpack.config.js

+20-23
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,38 @@
11
var webpack = require("webpack");
22
var path = require("path");
3-
var autoprefixer = require("autoprefixer");
43

54
module.exports = {
6-
devtool: "#inline-source-map",
5+
mode: "production",
6+
devtool: "source-map",
77
entry: {
8-
"docs.js": [
9-
"./docs/index.jsx"
10-
// 'webpack/hot/only-dev-server',
11-
// 'webpack-dev-server/client?http://localhost:8000'
12-
]
8+
"docs.js": "./docs/index.jsx"
139
},
1410
output: {
1511
path: path.join(__dirname, "build"),
1612
filename: "[name]"
1713
},
1814
module: {
19-
loaders: [
20-
{ test: /\.jsx$/, loaders: ["babel"] },
21-
{ test: /\.js$/, loaders: ["babel"], exclude: /node_modules/ },
15+
rules: [
2216
{
23-
test: /\.scss$/,
24-
loader:
25-
"style!css!sass?outputStyle=expanded&" +
26-
"includePaths[]=" +
27-
path.resolve(__dirname, "./node_modules")
17+
test: /\.jsx?/,
18+
exclude: /(node_modules)/,
19+
use: {
20+
loader: "babel-loader"
21+
}
2822
},
29-
{ test: /\.md$/, loader: "html!markdown" }
23+
{
24+
test: /\.md$/,
25+
loader: "html!markdown"
26+
}
3027
]
3128
},
32-
postcss: [autoprefixer({ browsers: ["last 2 version"] })],
3329
resolve: {
34-
extensions: ["", ".js", ".jsx"]
30+
extensions: [".js", ".jsx"]
3531
},
36-
plugins: [
37-
// new webpack.HotModuleReplacementPlugin(),
38-
new webpack.NoErrorsPlugin(),
39-
new webpack.IgnorePlugin(/vertx/)
40-
]
32+
plugins: [new webpack.IgnorePlugin(/vertx/)],
33+
devServer: {
34+
contentBase: path.join(__dirname, "./build"),
35+
port: 8080,
36+
hot: true
37+
}
4138
};

0 commit comments

Comments
 (0)
Please sign in to comment.