Skip to content

Commit bc22d0a

Browse files
committed
"fix: split app.js and increased performance"
1 parent 181fb8b commit bc22d0a

1 file changed

Lines changed: 30 additions & 5 deletions

File tree

frontend/webpack.config.prod.js

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,33 @@
11
const webpack = require('webpack')
2-
const ExtractTextPlugin = require('extract-text-webpack-plugin')
2+
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
33
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
4+
const HtmlWebpackPlugin = require('html-webpack-plugin')
5+
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
46
// Minify hangs in 92% when build in production, so now we are testing the uglify above
57
// const MinifyPlugin = require('babel-minify-webpack-plugin')
68

79
module.exports = {
810
mode: 'production',
911
optimization: {
1012
minimizer: [new UglifyJsPlugin()],
13+
runtimeChunk: 'single',
14+
splitChunks: {
15+
chunks: 'all',
16+
maxInitialRequests: Infinity,
17+
// minimum chunk size 30KB
18+
minSize: 30000,
19+
cacheGroups: {
20+
vendor: {
21+
test: /[\\/]node_modules[\\/](@material-ui)[\\/]/,
22+
name: 'vendor'
23+
},
24+
},
25+
},
1126
},
1227
entry: './src/index.js',
1328
output: {
1429
path: `${__dirname}/public`,
15-
filename: './app.js'
30+
filename: '[name].[hash].js'
1631
},
1732
resolve: {
1833
extensions: ['.js', '.jsx'],
@@ -23,14 +38,24 @@ module.exports = {
2338
},
2439
plugins: [
2540
// new MinifyPlugin(),
26-
new ExtractTextPlugin('app.css'),
41+
new HtmlWebpackPlugin({
42+
filename: `${__dirname}/public/index.html`,
43+
template: 'src/index.html',
44+
chunksSortMode: 'none'
45+
}),
46+
new MiniCssExtractPlugin({
47+
filename: 'app.css'
48+
}),
2749
new webpack.DefinePlugin({
2850
'process.env': {
2951
'NODE_ENV': JSON.stringify('production'),
3052
'API_HOST': JSON.stringify(process.env.API_HOST),
3153
'STRIPE_PUBKEY': JSON.stringify(process.env.STRIPE_PUBKEY),
3254
'SLACK_CHANNEL_INVITE_LINK': JSON.stringify(process.env.SLACK_CHANNEL_INVITE_LINK)
3355
}
56+
}),
57+
new CleanWebpackPlugin({
58+
cleanOnceBeforeBuildPatterns: ['!favicon-gitpay.ico']
3459
})
3560
],
3661
module: {
@@ -39,12 +64,12 @@ module.exports = {
3964
loader: 'babel-loader',
4065
exclude: /node_modules/,
4166
query: {
42-
presets: ['es2015', 'react'],
67+
presets: [['es2015', { 'modules': false }], 'react'],
4368
plugins: ['transform-object-rest-spread', 'transform-class-properties']
4469
}
4570
}, {
4671
test: /\.css$/,
47-
loader: ExtractTextPlugin.extract({ fallback: 'style-loader', use: 'css-loader' })
72+
use: [MiniCssExtractPlugin.loader, 'css-loader']
4873
}, {
4974
test: /\.(woff|woff2|ttf|eot|svg)$/,
5075
loader: 'file-loader'

0 commit comments

Comments
 (0)