-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.prod.js
81 lines (79 loc) · 2.74 KB
/
webpack.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
const path = require('path');
const merge = require('webpack-merge');
const webpack = require('webpack');
const TerserPlugin = require('terser-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const common = require('./webpack.common.js');
// This file contains webpack settings that are used for production.
// This includes:
// - Using content hashes for output filenames for cache busting.
// - Setting the PRODUCTION global variable to true.
// - High quality source maps
// - Custom overrides for the minifier to ensure it works in all browsers.
// - The ability to extract CSS from JS and TS files.
// - Splitting vendor (node_modules) code from application code.
// (This helps caching since vendor code is usually less likely to change than app code)
module.exports = merge.smart(common, {
mode: 'production',
devtool: 'source-map',
output: {
filename: '[name].[contenthash].js',
path: path.resolve(__dirname, 'dist'),
},
module: {
rules: [
{
test: /\.css$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
importLoaders: 1,
minimize: true,
},
},
],
},
],
},
plugins: [
new webpack.DefinePlugin({
PRODUCTION: JSON.stringify(true),
}),
new MiniCssExtractPlugin({
filename: '[name].[contenthash].css',
}),
new webpack.HashedModuleIdsPlugin(),
],
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
parallel: true,
sourceMap: true,
terserOptions: {
output: {
// Force ASCII characters so that Safari
// can load the worker blobs. (Safari loads them in ASCII mode)
// This is due to how AUX loads the web worker to ensure it uses a null origin
// and therefore does not have access to APIs such as IndexedDB.
ascii_only: true,
},
},
}),
new OptimizeCSSAssetsPlugin({}),
],
splitChunks: {
cacheGroups: {
vendor: {
test: /[\\/](node_modules|public)[\\/]/,
name: 'vendors',
chunks: 'all',
priority: 0,
},
},
},
},
});