-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.js
112 lines (107 loc) · 2.64 KB
/
webpack.config.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
const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const CompressionPlugin = require('compression-webpack-plugin')
const CopyPlugin = require('copy-webpack-plugin')
const { GenerateSW } = require('workbox-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
// const autoprefixer = require('autoprefixer')
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin')
const developmentPlugins = []
const productionPlugins = [
new CompressionPlugin({
filename: '[path][base].gz',
algorithm: 'gzip',
test: /\.js$|\.css$|\.html$/,
threshold: 10240,
minRatio: 0.8
// deleteOriginalAssets: true
}),
new CompressionPlugin({
filename: '[path][base].br',
algorithm: 'brotliCompress',
test: /\.(js|css|html|svg)$/,
// compressionOptions: {
// params: {
// [zlib.constants.BROTLI_PARAM_QUALITY]: 11
// }
// },
threshold: 10240,
minRatio: 0.8
}),
new OptimizeCSSAssetsPlugin({
cssProcessorOptions: {
safe: true,
discardComments: {
removeAll: true
}
}
})
]
module.exports = (env, { mode }) => ({
// entry: path.resolve(__dirname, './lib/index.ts'),
entry: path.resolve(__dirname, 'lib', 'index.ts'),
output: {
filename: '[name].[contenthash].js',
publicPath: '/'
},
optimization: {
runtimeChunk: 'single',
splitChunks: {
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/]/,
name: 'vendors',
chunks: 'all'
}
}
}
},
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/
},
{
test: /\.(css|styl)$/,
use: [
MiniCssExtractPlugin.loader,
'css-loader?importLoaders=true'
]
},
{
test: /\.html$/,
use: ['html-loader']
}
]
},
resolve: {
extensions: ['.tsx', '.ts', '.js', '.css']
},
plugins: [
...(mode === 'production' ? productionPlugins : developmentPlugins),
new HtmlWebpackPlugin({
template: path.resolve(__dirname, 'src', 'index.html')
}),
new CopyPlugin({
patterns: [
{
from: '**/*',
to: path.resolve(__dirname, 'dist'),
context: path.resolve(__dirname, 'static')
}
]
}),
new MiniCssExtractPlugin({
filename: '[name].[contenthash].css',
chunkFilename: '[name].[contenthash].css'
}),
new GenerateSW({
clientsClaim: true,
skipWaiting: true,
sourcemap: true,
navigateFallback: '/index.html'
})
].filter(Boolean)
})