-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.prod.js
64 lines (58 loc) · 1.89 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
const path = require('path');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const CopyPlugin = require('copy-webpack-plugin');
const TerserJSPlugin = require('terser-webpack-plugin');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const { merge } = require('webpack-merge');
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
const { InjectManifest } = require('workbox-webpack-plugin');
const { env } = require('process');
const baseConfig = require('./webpack.config.base.js');
const { ANALYZE_BUNDLE: isAnalyzeBundleEnabled } = env;
const {
output: { path: outputPath },
} = baseConfig;
module.exports = merge(baseConfig, {
mode: 'production',
optimization: {
minimizer: [new TerserJSPlugin({}), new OptimizeCSSAssetsPlugin({})],
},
plugins: [
new CleanWebpackPlugin(),
new CopyPlugin({
patterns: [
// Netlify custom headers file and redirects
{
from: path.join(__dirname, '_headers'),
to: path.join(outputPath, '_headers'),
toType: 'file',
},
{
from: path.join(__dirname, '_redirects'),
to: path.join(outputPath, '_redirects'),
toType: 'file',
},
{
from: path.join(__dirname, './src/robots.txt'),
to: path.join(outputPath, 'robots.txt'),
toType: 'file',
},
],
}),
new InjectManifest({
swSrc: './src/sw.js',
globPatterns: [
path.join(outputPath, './*.{js,svg,html,css,webp,jpg}'),
path.join(outputPath, './manifest.json'),
path.join(outputPath, './static/logo/*'),
],
exclude: ['_headers', '_redirects', 'robots.txt'],
}),
isAnalyzeBundleEnabled && new BundleAnalyzerPlugin(),
].filter(plugin => !!plugin),
performance: {
maxAssetSize: 175000,
maxEntrypointSize: 175000,
hints: 'error',
},
});