This repository has been archived by the owner on May 22, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.js
99 lines (93 loc) · 2.46 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
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const history = require('connect-history-api-fallback');
const convert = require('koa-connect');
const WorkboxPlugin = require('workbox-webpack-plugin');
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
const WebpackBar = require('webpackbar');
const isProd = process.env.NODE_ENV === 'production';
module.exports = {
mode: isProd ? 'production' : 'development',
entry: './src/Index.bs',
output: {
path: path.resolve(__dirname, './dist'),
filename: !isProd ? '[name].js' : '[name].[chunkhash:8].js',
publicPath: '/'
},
plugins: [
new WebpackBar(),
new HtmlWebpackPlugin({
title: 'Webpack ReasonML',
inject: true,
template: './public/index.html'
}),
new WorkboxPlugin.GenerateSW({
swDest: 'sw.js',
clientsClaim: true,
skipWaiting: true,
// Exclude images from the precache
exclude: [/\.(?:png|jpg|jpeg|svg)$/],
// Define runtime caching rules.
runtimeCaching: [
{
urlPattern: /^(https?.*)/,
handler: 'networkFirst',
options: {
cacheName: 'cache-https',
expiration: {
maxEntries: 50
},
networkTimeoutSeconds: 3
}
},
{
// Match any request ends with .png, .jpg, .jpeg or .svg.
urlPattern: /\.(?:png|jpg|jpeg|svg)$/,
// Apply a cache-first strategy.
handler: 'cacheFirst',
options: {
cacheName: 'images-cache',
// Only cache 10 images.
expiration: {
maxEntries: 50
},
cacheableResponse: {
statuses: [0, 200]
}
}
}
]
}),
...(isProd ? [new BundleAnalyzerPlugin()] : [])
],
optimization: {
splitChunks: {
cacheGroups: {
commons: {
test: /node_modules/,
chunks: 'initial',
name: 'vendor',
priority: 10,
enforce: true
}
}
}
},
stats: {
colors: true,
reasons: isProd,
timings: true
}
};
if (!isProd) {
module.exports.serve = {
content: [__dirname],
port: 8888,
add: (app, middleware, options) => {
const historyOptions = {
// ... see: https://github.com/bripkens/connect-history-api-fallback#options
};
app.use(convert(history(historyOptions)));
}
};
}