Skip to content

Commit faaadd9

Browse files
committed
Upgrade Webpack to v4 and add babel-loader
Babel-loader will bridge the gap between our Node 8-compatible syntax and modern web browsers (as well as less-modern ones like IE 11)
1 parent a85e96f commit faaadd9

File tree

3 files changed

+52
-13
lines changed

3 files changed

+52
-13
lines changed

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"cms",
2323
"wordpress"
2424
],
25+
"browserslist": "last 2 versions, ie 11, not dead",
2526
"jest": {
2627
"testMatch": [
2728
"**/__tests__/**/*.js",
@@ -66,6 +67,9 @@
6667
"superagent": "^3.3.1"
6768
},
6869
"devDependencies": {
70+
"@babel/core": "^7.2.2",
71+
"@babel/plugin-proposal-object-rest-spread": "^7.2.0",
72+
"@babel/preset-env": "^7.2.3",
6973
"babel-loader": "^8.0.4",
7074
"combyne": "^2.0.0",
7175
"eslint": "^4.19.1",
@@ -83,6 +87,7 @@
8387
"minimist": "^1.2.0",
8488
"prompt": "^1.0.0",
8589
"rimraf": "^2.6.1",
86-
"webpack": "^4.28.1"
90+
"webpack": "^4.28.1",
91+
"webpack-cli": "^3.1.2"
8792
}
8893
}

webpack.config.js

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,45 @@
11
'use strict';
22

3-
const path = require( 'path' );
4-
const outputPath = path.join( __dirname, 'browser' );
3+
const { join } = require( 'path' );
54

65
module.exports = {
76
entry: './wpapi.js',
87

9-
devtool: 'source-map',
8+
mode: 'development',
9+
10+
devtool: 'cheap-module-source-map',
11+
12+
stats: {
13+
all: false,
14+
assets: true,
15+
colors: true,
16+
errors: true,
17+
performance: true,
18+
timings: true,
19+
warnings: true,
20+
},
1021

1122
output: {
12-
path: outputPath,
23+
path: join( process.cwd(), 'browser' ),
1324
filename: 'wpapi.js',
1425
library: 'WPAPI',
1526
libraryTarget: 'umd',
1627
},
28+
29+
module: {
30+
rules: [
31+
{
32+
test: /\.js$/,
33+
exclude: /(node_modules|bower_components)/,
34+
loader: require.resolve( 'babel-loader' ),
35+
options: {
36+
presets: [ '@babel/preset-env' ],
37+
plugins: [ '@babel/plugin-proposal-object-rest-spread' ],
38+
// Cache compilation results in ./node_modules/.cache/babel-loader/
39+
cacheDirectory: true,
40+
},
41+
},
42+
],
43+
},
44+
1745
};

webpack.config.minified.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
'use strict';
22

3-
const webpack = require( 'webpack' );
43
const config = require( './webpack.config' );
54

65
// Re-use normal Webpack build config, just adding minification
7-
config.output.filename = 'wpapi.min.js';
8-
config.plugins = config.plugins || [];
9-
config.plugins.push( new webpack.optimize.UglifyJsPlugin( {
10-
compress: {
11-
warnings: false,
6+
module.exports = {
7+
...config,
8+
9+
mode: 'production',
10+
11+
devtool: 'hidden-source-map',
12+
13+
output: {
14+
...config.output,
15+
filename: 'wpapi.min.js',
1216
},
13-
} ) );
1417

15-
module.exports = config;
18+
optimization: {
19+
noEmitOnErrors: true,
20+
},
21+
};

0 commit comments

Comments
 (0)