-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.prod.config.babel.js
94 lines (90 loc) · 2.71 KB
/
webpack.prod.config.babel.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
const webpack = require('webpack');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer')
.BundleAnalyzerPlugin;
const ScriptExtHtmlWebpackPlugin = require('script-ext-html-webpack-plugin');
const StyleExtHtmlWebpackPlugin = require('style-ext-html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const InlineManifestWebpackPlugin = require('inline-manifest-webpack-plugin');
const WorkboxPlugin = require('workbox-webpack-plugin');
const prodPlugins = [
// Move Files
new CopyWebpackPlugin([
{ from: 'public/manifest.json' },
{ from: 'public/sitemap.xml' },
{ from: 'content', to: 'content' },
{
from: 'src/assets',
to: 'assets',
ignore: ['**/*.svg', 'src/assets/svg/*', '*.svg']
}
]),
// Todo check the options
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
minChunks: m => m.context && m.context.includes('node_modules')
}),
//CommonChunksPlugin will now extract all the common modules from vendor and main bundles
new webpack.optimize.CommonsChunkPlugin({
name: 'manifest',
minChunks: Infinity //But since there are no more common modules between them we end up with just the runtime code included in the manifest file
}),
new InlineManifestWebpackPlugin({
name: 'webpackManifest'
}),
// Webpack 3 Scope Hoisting
new webpack.optimize.ModuleConcatenationPlugin(),
// Inline CSS
new StyleExtHtmlWebpackPlugin({
minify: true
}),
// Add Async Tags
new ScriptExtHtmlWebpackPlugin({
defaultAttribute: 'defer'
//async: ['app']
}),
// Specific Options for Loading
new webpack.LoaderOptionsPlugin({ minimize: true, debug: false }),
// Minimize JS
new webpack.optimize.UglifyJsPlugin({
beatify: false,
mangle: {
screw_ie8: true
},
compress: {
warnings: false,
screw_ie8: true,
conditionals: true,
unused: true,
comparisons: true,
sequences: true,
dead_code: true,
evaluate: true,
if_return: true,
join_vars: true,
drop_console: false
},
comments: false,
output: { comments: false },
sourceMap: true,
minimize: true
}),
// Clean up dist folder after each build
new CleanWebpackPlugin(['dist'], {
root: __dirname,
verbose: true,
dry: false
}),
// Add Service Worker
new WorkboxPlugin.GenerateSW({
skipWaiting: true,
clientsClaim: true
}),
//Add Bundle JS Analyzer
new BundleAnalyzerPlugin({
analyzerMode: 'static',
openAnalyzer: true,
generateStatsFile: false
})
];
module.exports = prodPlugins;