-
Notifications
You must be signed in to change notification settings - Fork 7
/
webpack.production.config.js
63 lines (53 loc) · 1.56 KB
/
webpack.production.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
const webpack = require('webpack');
const CSPPlugin = require('csp-html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const { SubresourceIntegrityPlugin } = require('webpack-subresource-integrity');
const config = require('./webpack.config');
// Hash all JS assets
config.output.filename = '[name].[contenthash].min.js';
// Remove devServer config
delete config.devServer;
// Remove NoEmitOnErrors, HotModuleReplacement and Dashboard plugins
config.plugins.shift();
config.plugins.shift();
// Remove source mapping
config.devtool = 'source-map';
// Add production plugins
config.plugins.unshift(
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: '"production"',
},
}),
new MiniCssExtractPlugin({
filename: '[name].[contenthash].css',
chunkFilename: 'chunk.[id].[contenthash].css',
// allChunks: true,
}),
new OptimizeCssAssetsPlugin());
config.plugins.push(
new CSPPlugin({
'base-uri': "'self'",
'object-src': "'none'",
'script-src': ["'unsafe-inline'", "'self'"],
'style-src': ["'unsafe-inline'", "'self'", "https://fonts.googleapis.com"]
}, {
enabled: true,
hashingMethod: 'sha256',
hashEnabled: {
'script-src': true,
'style-src': false
},
nonceEnabled: {
'script-src': true,
'style-src': false
}
}),
new SubresourceIntegrityPlugin({
hashFuncNames: ['sha256', 'sha384'],
enabled: true,
}),
);
config.mode = 'production';
module.exports = config;