-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.prod.js
107 lines (106 loc) · 2.8 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
const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const TerserWeppackPlugin = require('terser-webpack-plugin')
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin')
const postcssSafeParser = require('postcss-safe-parser')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const merge = require('webpack-merge')
const base = require('./webpack.config.base')
module.exports = merge(base, {
mode: 'production',
devtool: 'source-map',
output: {
filename: 'static/js/main.[hash:8].js',
chunkFilename: 'static/js/[name].chunk.[hash:8].js',
path: path.resolve(__dirname, 'build'),
},
module: {
rules: [
{
// css-loader
test: /\.css$/,
use: [MiniCssExtractPlugin.loader, 'css-loader', 'postcss-loader'],
},
{
// sass/scss loader to load sass-scss style files
test: /\.(sass|scss)$/,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
'postcss-loader',
'sass-loader',
],
},
{
// copies image files to assets folder in destination folder - build
test: /\.(svg|png|jpg|jpeg|gif|mp3|ico)$/,
use: [
{
loader: 'file-loader',
options: {
name: '[name].[hash:8].[ext]',
outputPath: 'static/assets',
},
},
],
},
],
},
optimization: {
minimizer: [
new TerserWeppackPlugin({
terserOptions: {
parse: {
ecma: 8,
},
compress: {
ecma: 5,
warnings: false,
comparisons: false,
inline: 2,
},
mangle: {
safari10: true,
},
output: {
ecma: 5,
comments: false,
ascii_only: true,
},
},
parallel: true,
cache: true,
sourceMap: true,
}),
],
},
plugins: [
new HtmlWebpackPlugin({
template: path.join(__dirname, 'public', 'index.html'),
favicon: path.resolve(__dirname, 'public', 'favicon.ico'),
minify: {
removeComments: true,
collapseWhitespace: true,
removeRedundantAtributes: true,
useShortDoctype: true,
removeEmptyAttributes: true,
removeStyleLinkTypeAttributes: true,
keepClosingSlash: true,
minifyJS: true,
minifyCSS: true,
minifyURLs: true,
},
}),
new MiniCssExtractPlugin({
filename: 'static/css/[name].[hash:8].css',
}),
new OptimizeCSSAssetsPlugin({
cssProcessorOptions: {
parser: postcssSafeParser,
map: true,
},
}),
new CleanWebpackPlugin(),
],
})