forked from suryamak/tune-chef
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.prod.js
119 lines (112 loc) · 3.08 KB
/
webpack.config.prod.js
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import webpack from 'webpack';
// import MiniCssExtractPlugin from 'mini-css-extract-plugin';
import WebpackMd5Hash from 'webpack-md5-hash';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import path from 'path';
import CopyWebpackPlugin from 'copy-webpack-plugin';
const GLOBALS = {
'process.env.NODE_ENV': JSON.stringify('production'),
__DEV__: false,
};
export default {
stats: 'errors-only',
resolve: {
extensions: ['*', '.js', '.jsx', '.json'],
},
devtool: 'source-map', // more info:https://webpack.js.org/guides/production/#source-mapping and https://webpack.js.org/configuration/devtool/
entry: [
'idempotent-babel-polyfill',
path.resolve(__dirname, 'app/index'),
],
target: 'web',
mode: 'production',
performance: {
hints: false,
},
output: {
path: path.resolve(__dirname, 'dist'),
publicPath: '/',
filename: '[name].[chunkhash].js',
},
plugins: [
// Hash the files using MD5 so that their names change when the content changes.
new WebpackMd5Hash(),
// Makes sure the file hashes don't change unexpectedly
new webpack.HashedModuleIdsPlugin(),
// Tells React to build in prod mode. https://facebook.github.io/react/downloads.html
new webpack.DefinePlugin(GLOBALS),
// add the favicon
new CopyWebpackPlugin([
{ from: './favicon.ico' },
]),
// Generate an external css file with a hash in the filename
// Generate HTML file that contains references to generated bundles. See here for how this works: https://github.com/ampedandwired/html-webpack-plugin#basic-usage
new HtmlWebpackPlugin({
template: './app/index.html',
filename: 'index.html',
// favicon: 'src/favicon.ico',
minify: {
removeComments: true,
collapseWhitespace: true,
removeRedundantAttributes: true,
useShortDoctype: true,
removeEmptyAttributes: true,
removeStyleLinkTypeAttributes: true,
keepClosingSlash: true,
minifyJS: true,
minifyCSS: true,
minifyURLs: true,
},
hash: true,
inject: false,
}),
],
optimization: {
splitChunks: {
chunks: 'all',
minSize: 100000,
maxSize: 450000,
},
},
module: {
rules: [
{
test: /\.js$/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/env', '@babel/react'],
plugins: ['@babel/plugin-proposal-object-rest-spread'],
},
},
},
{
test: /\.css$/,
loader: 'style-loader',
}, {
test: /\.css$/,
loader: 'css-loader',
query: {
modules: true,
localIdentName: '[name]__[local]___[hash:base64:5]&camelCase',
},
}, {
test: /\.css$/,
loader: 'postcss-loader',
}, {
test: /\.(png|jpg|gif|mp3)$/i,
use: [
{
loader: 'url-loader',
options: {
limit: 8192,
},
},
],
}, {
test: /\.svg$/,
loaders: ['@svgr/webpack', 'url-loader'],
},
],
},
};