Skip to content

Commit beca226

Browse files
committed
Restructure webpack configuration files.
Config files have been reorganized to be easier to understand. Also, babel-polyfill has been reconfigured to make the bundle smaller and to meet the new core-js version requirements.
1 parent c59b8f5 commit beca226

File tree

14 files changed

+5323
-8280
lines changed

14 files changed

+5323
-8280
lines changed

.babelrc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
"targets": {
55
"node": "current",
66
"browsers": ["last 2 versions", "IE 11"]
7-
}
7+
},
8+
"useBuiltIns": "usage",
9+
"corejs": "3"
810
}],
911
"@babel/preset-react"
1012
],

package-lock.json

Lines changed: 5211 additions & 8117 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
"start": "cross-env NODE_ENV=development babel-node src/index",
88
"watch": "cross-env NODE_ENV=development nodemon src/index",
99
"build": "npm-run-all -p build:client build:server build:node",
10-
"build:client": "cross-env NODE_ENV=production webpack -p --config webpack/client.production.js",
11-
"build:server": "cross-env NODE_ENV=production webpack -p --config webpack/server.production.js",
12-
"build:node": "cross-env NODE_ENV=production webpack -p --config webpack/node.production.js",
10+
"build:client": "cross-env NODE_ENV=production webpack --config webpack/client/prod.js",
11+
"build:server": "cross-env NODE_ENV=production webpack --config webpack/server/prod.js",
12+
"build:node": "cross-env NODE_ENV=production webpack --config webpack/node.js",
1313
"test": "jest",
1414
"lint": "eslint src/**/*.js"
1515
},
@@ -34,6 +34,7 @@
3434
"dependencies": {
3535
"@babel/polyfill": "^7.4.3",
3636
"copy-webpack-plugin": "^5.0.2",
37+
"core-js": "^3.0.1",
3738
"express": "^4.16.4",
3839
"helmet": "^3.16.0",
3940
"react": "^16.8.6",
@@ -45,7 +46,7 @@
4546
},
4647
"devDependencies": {
4748
"@babel/core": "^7.4.3",
48-
"@babel/node": "^7.0.0",
49+
"@babel/node": "^7.2.2",
4950
"@babel/plugin-proposal-class-properties": "^7.4.0",
5051
"@babel/plugin-proposal-decorators": "^7.4.0",
5152
"@babel/plugin-syntax-dynamic-import": "^7.2.0",

src/index.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import express from 'express';
22
import helmet from 'helmet';
3-
import shrinkRay from 'shrink-ray';
43
import { join } from 'path';
54
import { log } from 'winston';
65

@@ -11,8 +10,8 @@ import { log } from 'winston';
1110
* @param app Express app
1211
*/
1312
const configureDevelopment = (app) => {
14-
const clientConfig = require('../webpack/client');
15-
const serverConfig = require('../webpack/server');
13+
const clientConfig = require('../webpack/client/dev');
14+
const serverConfig = require('../webpack/server/dev');
1615
const { publicPath, path } = clientConfig.output;
1716

1817
const multiCompiler = require('webpack')([clientConfig, serverConfig]);
@@ -54,9 +53,6 @@ const isDevelopment = process.env.NODE_ENV === 'development';
5453

5554
log('info', `Configuring server for environment: ${process.env.NODE_ENV}...`);
5655
app.use(helmet());
57-
app.use(shrinkRay({
58-
filter: () => !isDevelopment,
59-
}));
6056
app.set('port', process.env.PORT || 3000);
6157

6258
if (isDevelopment) {

webpack/client.js

Lines changed: 0 additions & 58 deletions
This file was deleted.
Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
const merge = require('webpack-merge');
2-
const common = require('./common');
3-
const { join } = require('path');
2+
const common = require('../common');
43
const ExtractCssChunksPlugin = require('extract-css-chunks-webpack-plugin');
5-
const StatsWebpackPlugin = require('stats-webpack-plugin');
64

75
module.exports = merge(common, {
8-
mode: 'production',
96
name: 'client',
107
target: 'web',
11-
entry: [join(__dirname, '../src/client/index')],
12-
devtool: 'hidden-source-map',
138
output: {
149
filename: 'app.client.js',
15-
chunkFilename: '[name].chunk.js'
10+
chunkFilename: '[name].chunk.js',
1611
},
1712
module: {
1813
rules: [
@@ -26,30 +21,29 @@ module.exports = merge(common, {
2621
options: {
2722
modules: true,
2823
localIdentName: '[name]__[local]--[hash:base64:5]'
29-
}
24+
},
3025
},
3126
'postcss-loader',
32-
'stylus-loader'
33-
]
34-
}
35-
]
27+
'stylus-loader',
28+
],
29+
},
30+
],
3631
},
3732
optimization: {
3833
runtimeChunk: {
39-
name: 'bootstrap'
34+
name: 'bootstrap',
4035
},
4136
splitChunks: {
4237
chunks: 'initial',
4338
cacheGroups: {
4439
vendors: {
4540
test: /[\\/]node_modules[\\/]/,
46-
name: 'vendor'
47-
}
48-
}
49-
}
41+
name: 'vendor',
42+
},
43+
},
44+
},
5045
},
5146
plugins: [
5247
new ExtractCssChunksPlugin(),
53-
new StatsWebpackPlugin('stats.json')
54-
]
48+
],
5549
});

webpack/client/dev.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const { join } = require('path');
2+
const webpack = require('webpack');
3+
const merge = require('webpack-merge');
4+
5+
const common = require('./common');
6+
7+
module.exports = merge(common, {
8+
mode: 'development',
9+
entry: [
10+
'webpack-hot-middleware/client',
11+
join(__dirname, '../../src/client/index'),
12+
],
13+
devtool: 'cheap-eval-module-source-map',
14+
plugins: [
15+
new webpack.HotModuleReplacementPlugin(),
16+
],
17+
});

webpack/client/prod.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const { join } = require('path');
2+
const merge = require('webpack-merge');
3+
const StatsWebpackPlugin = require('stats-webpack-plugin');
4+
5+
const common = require('./common');
6+
7+
module.exports = merge(common, {
8+
mode: 'production',
9+
entry: [
10+
join(__dirname, '../../src/client/index'),
11+
],
12+
devtool: 'source-map',
13+
plugins: [
14+
new StatsWebpackPlugin('stats.json'),
15+
],
16+
});

webpack/common.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,25 @@ const WebpackBar = require('webpackbar');
44
module.exports = {
55
output: {
66
path: join(__dirname, '../public/assets'),
7-
publicPath: '/'
7+
publicPath: '/',
88
},
99
resolve: {
1010
extensions: ['.js'],
11-
modules: [join(__dirname, '../node_modules'), join(__dirname, '../src')]
11+
modules: [
12+
join(__dirname, '../node_modules'),
13+
join(__dirname, '../src')
14+
],
1215
},
1316
module: {
1417
rules: [
1518
{
1619
test: /\.js$/,
1720
exclude: /node_modules/,
1821
use: 'babel-loader'
19-
}
20-
]
22+
},
23+
],
2124
},
2225
plugins: [
23-
new WebpackBar()
24-
]
26+
new WebpackBar(),
27+
],
2528
};
Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
const merge = require('webpack-merge');
2-
const common = require('./common');
31
const { join } = require('path');
42
const CopyPlugin = require('copy-webpack-plugin');
3+
const merge = require('webpack-merge');
54

5+
const common = require('./common');
66
const extendedNodeExternals = require('../scripts/extended-node-externals');
77

88
module.exports = merge(common, {
@@ -11,19 +11,21 @@ module.exports = merge(common, {
1111
externals: extendedNodeExternals,
1212
node: {
1313
__dirname: false,
14-
__filename: false
14+
__filename: false,
1515
},
16-
entry: ['@babel/polyfill', join(__dirname, '../src/index')],
16+
entry: [
17+
join(__dirname, '../src/index')
18+
],
1719
output: {
1820
filename: 'index.js',
19-
path: join(__dirname, '../public')
21+
path: join(__dirname, '../public'),
2022
},
2123
plugins: [
2224
new CopyPlugin([
2325
{
2426
from: join(__dirname, '../package.json'),
2527
to: join(__dirname, '../public/package.json')
26-
}
27-
])
28-
]
28+
},
29+
]),
30+
],
2931
});

0 commit comments

Comments
 (0)