This repository was archived by the owner on Sep 24, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 102
/
Copy pathwebpack.config.prod.js
107 lines (101 loc) · 2.6 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 UglifyJsPlugin = require('uglifyjs-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const CompressionPlugin = require('compression-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const FaviconsWebpackPlugin = require('favicons-webpack-plugin')
const webpackConfig = require('./webpack.config.base')
const helpers = require('./helpers')
const DefinePlugin = require('webpack/lib/DefinePlugin')
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin')
const env = require('../environment/prod.env')
webpackConfig.mode = "production"
webpackConfig.module.rules = [...webpackConfig.module.rules,
{
test: /\.(sa|sc|c)ss$/,
use: [
process.env.NODE_ENV !== 'production' ? 'style-loader' : 'MiniCssExtractPlugin.loader',
'css-loader',
'sass-loader'
]
},
{
test: /\.(jpg|png|gif)$/,
loader: 'file-loader',
options: {
regExp: /(img\/.*)/,
name: '[name].[ext]',
publicPath: '../',
outputPath: 'assets/img/'
}
},
{
test: /\.(eot|svg|ttf|woff|woff2)$/,
loader: 'file-loader',
options: {
regExp: /(fonts\/.*)/,
name: '[name].[ext]',
publicPath: '../',
outputPath: 'fonts/'
}
}
]
// ensure ts lint fails the build
webpackConfig.module.rules[0].options = {
failOnHint: true
}
webpackConfig.optimization = {
splitChunks: {
cacheGroups: {
commons: {
test: /[\\/]node_modules[\\/]/,
name: 'vendors',
chunks: 'all'
}
}
},
minimizer: [
new UglifyJsPlugin()
]
}
webpackConfig.plugins = [...webpackConfig.plugins,
new MiniCssExtractPlugin({
filename: "[name].css",
chunkFilename: "[id].css"
}),
new OptimizeCssAssetsPlugin({
cssProcessor: require('cssnano'),
cssProcessorOptions: {
discardUnused: false,
discardComments: {
removeAll: true
}
},
canPrint: true
}),
new HtmlWebpackPlugin({
inject: true,
template: helpers.root('/src/index.html'),
favicon: helpers.root('/src/favicon.ico'),
minify: {
removeComments: true,
collapseWhitespace: true,
removeRedundantAttributes: true,
useShortDoctype: true,
removeEmptyAttributes: true,
removeStyleLinkTypeAttributes: true,
keepClosingSlash: true,
minifyJS: true,
minifyCSS: true,
minifyURLs: true
}
}),
new CompressionPlugin({
asset: '[path].gz[query]',
test: /\.js$/
}),
new DefinePlugin({
'process.env': env
}),
new FaviconsWebpackPlugin(helpers.root('/src/icon.png'))
]
module.exports = webpackConfig