-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
118 lines (111 loc) · 3.18 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
113
114
115
116
117
118
const CopyPlugin = require('copy-webpack-plugin');
const Critters = require('critters-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CompressionPlugin = require('compression-webpack-plugin');
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
const WorkboxPlugin = require('workbox-webpack-plugin');
module.exports = {
mode: 'production',
entry: './src/scripts/main.js',
output: {
clean: true,
filename: '[name].[contenthash].js',
chunkFilename: '[id].[contenthash].js',
},
module: {
rules: [
{
test: /\.css$/,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
],
},
],
},
optimization: {
minimizer: [
'...',
new CssMinimizerPlugin(),
],
},
plugins: [
new MiniCssExtractPlugin({
filename: '[name].[contenthash].css',
}),
new CopyPlugin({
patterns: [
{ from: './src/assets', to: 'assets' },
{ from: './src/pages' },
]
}),
new HtmlWebpackPlugin({
minify: true,
inject: 'body',
favicon: './src/favicon.ico',
template: './src/index.html',
}),
/**
* Compress output assets using Brotli algorithm.
* Support - https://caniuse.com/brotli
* https://webpack.js.org/plugins/compression-webpack-plugin/#using-brotli
*/
new CompressionPlugin({
algorithm: 'brotliCompress',
}),
/**
* Inline critical CSS.
* https://github.com/GoogleChromeLabs/critters
*/
new Critters({
pruneSource: true, // Remove inlined rules from the external stylesheet.
}),
/**
* Progressive Web Application.
* https://webpack.js.org/guides/progressive-web-application/
* https://developer.chrome.com/docs/workbox/modules/workbox-webpack-plugin/
*/
new WorkboxPlugin.GenerateSW({
skipWaiting: true,
clientsClaim: true,
/**
* Pre-caching with Workbox:
* https://developer.chrome.com/docs/workbox/precaching-with-workbox/
*
* Pre-caching dos and don'ts:
* https://developer.chrome.com/docs/workbox/precaching-dos-and-donts/
*/
additionalManifestEntries: [
'contact/', // Contact page will be pre-cached.
],
// Pre-cache CSS and JS files generated by webpack before activating the service worker.
manifestTransforms: [
manifestEntries => ({
manifest: manifestEntries.filter(entry => /.(css|js)$/.test(entry.url)),
})
],
// Configure which requests should be intercepted and how to handle them.
runtimeCaching: [
{
urlPattern: ({ request }) => request.destination === 'document',
handler: 'StaleWhileRevalidate',
options: {
cacheName: 'pages',
},
},
{
urlPattern: ({ request }) => request.destination === 'image',
handler: 'NetworkFirst',
options: {
cacheName: 'images',
expiration: {
maxEntries: 20,
purgeOnQuotaError: true,
},
},
},
],
}),
],
};