forked from techqueria/website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.prod.js
101 lines (99 loc) 路 2.42 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
const webpack = require("webpack");
const path = require("path");
// Workbox
const WorkboxPlugin = require("workbox-webpack-plugin");
// Brotli
const BrotliPlugin = require("brotli-webpack-plugin");
// GZip
const CompressionPlugin = require("compression-webpack-plugin");
module.exports = {
mode: "production",
module: {
rules: [{
test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: "url-loader"
},
{
test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-c9])?$/,
loader: "url-loader"
},
{
test: /\.js?$/,
loader: "babel-loader",
exclude: /node_modules/,
query: {
cacheDirectory: true
}
},
{
test: /\.css$/,
use: ["style-loader", "css-loader"]
},
{
test: /\.(gif|png|jpe?g|svg)$/i,
use: [
"file-loader",
{
loader: "image-webpack-loader"
}
]
}
]
},
plugins: [
new webpack.optimize.ModuleConcatenationPlugin(),
new webpack.ProvidePlugin({
fetch: "imports-loader?this=>global!exports?global.fetch!whatwg-fetch"
}),
new webpack.optimize.AggressiveMergingPlugin(),
new BrotliPlugin(),
new CompressionPlugin(),
new WorkboxPlugin.GenerateSW({
cacheId: "techqueria",
swDest: "sw.js",
globDirectory: "./dist",
globPatterns: ["index.html", "404.html", "**/*.{js,css,png,svg,jpg,jpeg,icon,json}"],
offlineGoogleAnalytics: true,
clientsClaim: true,
skipWaiting: true,
runtimeCaching: [{
urlPattern: /\.(?:html)$/,
handler: "networkFirst",
options: {
cacheName: "page-cache",
expiration: {
maxEntries: 50
},
}
},
{
urlPattern: /\.(?:png|gif|jpg|svg|ico|jpeg|css|js)$/,
handler: "cacheFirst",
options: {
cacheName: "assets-cache"
}
},
{
urlPattern: new RegExp("https://twemoji.maxcdn.com"),
handler: "staleWhileRevalidate"
},
{
urlPattern: new RegExp("https://i.imgur.com"),
handler: "staleWhileRevalidate"
},
{
urlPattern: new RegExp("https://www.google-analytics.com"),
handler: "staleWhileRevalidate"
}
]
})
],
context: path.join(__dirname, "src"),
entry: {
app: ["./js/app"]
},
output: {
filename: path.join("assets", "js", "[name].js"),
path: path.join(__dirname, "dist"),
}
};