-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathwebpack.config.prod.babel.js
More file actions
101 lines (99 loc) · 2.93 KB
/
webpack.config.prod.babel.js
File metadata and controls
101 lines (99 loc) · 2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
let path = require('path');
let common_config = require('./webpack.config.common.babel');
let APP_DIR = common_config.APP_DIR;
let COMMON_LOADERS = common_config.COMMON_LOADERS;
let webpack = require('webpack');
const TerserPlugin = require('terser-webpack-plugin');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const HtmlWebpackExternalsPlugin = require('html-webpack-externals-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
let config = {
mode: 'production',
// disable verbose logs. https://github.com/webpack-contrib/mini-css-extract-plugin/issues/39
stats: {
entrypoints: false,
children: false,
},
resolve: common_config.getResolve(true),
entry: {
app: APP_DIR + '/main-prod.js',
},
// http://cheng.logdown.com/posts/2016/03/25/679045
devtool: 'cheap-module-source-map',
output: common_config.getOutput(true),
module: {
rules: [
common_config.getEsLintLoader(true),
...common_config.getCommonLoaders(true),
...common_config.getBabelLoader(true),
common_config.getCssLoaders(true),
],
},
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
terserOptions: {
compress: {
drop_console: true,
},
},
}),
new OptimizeCSSAssetsPlugin({
cssProcessorOptions: {
safe: true,
},
}),
],
},
plugins: [
new CleanWebpackPlugin(
[
'dist',
]
),
new MiniCssExtractPlugin({
filename: 'css/[name].[contenthash].css',
}),
// ensure that we get a production build of any dependencies
// this is primarily for React, where this removes 179KB from the bundle
new webpack.DefinePlugin({
'process.env.NODE_ENV': '"production"',
__DEV__: false,
}),
new HtmlWebpackPlugin({
template: 'src/index.hbs',
baseUrl: 'https://slothtoss.com',
}),
new HtmlWebpackExternalsPlugin({
// don't bundle these libraries; we use them from the CDN
externals: [
{
module: 'react',
entry: {
path: 'https://unpkg.com/react@16.7.0/umd/react.production.min.js',
attributes: {
integrity: 'sha384-bDWFfmoLfqL0ZuPgUiUz3ekiv8NyiuJrrk1wGblri8Nut8UVD6mj7vXhjnenE9vy',
crossorigin: 'anonymous',
},
},
global: 'React',
},
{
module: 'react-dom',
entry: {
path: 'https://unpkg.com/react-dom@16.7.0/umd/react-dom.production.min.js',
attributes: {
integrity: 'sha384-mcyjbblFFAXUUcVbGLbJZR86Xd7La0uD1S7/Snd1tW0N+zhy97geTqVYDQ92c8tI',
crossorigin: 'anonymous',
},
},
global: 'ReactDOM',
},
],
}),
],
};
module.exports = config;