-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnext.config.js
66 lines (62 loc) · 1.51 KB
/
next.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
const NextWorkboxPlugin = require('next-workbox-webpack-plugin');
const { name, title, description, author, home } = require('./package.json');
const IS_PROD = process.env.NODE_ENV === 'production';
const BASE_URL = IS_PROD ? home : 'http://localhost:3000';
const UA_ID = process.env.UA_ID || 'UA-XXXXXXXXX-1';
module.exports = {
env: {
IS_PROD,
BASE_URL,
UA_ID,
name,
title,
description,
author,
},
webpack(config, { isServer, dev, buildId, config: { distDir } }) {
config.node = {
fs: 'empty',
};
const workboxOptions = {
clientsClaim: true,
skipWaiting: true,
globPatterns: ['.next/static/*', '.next/static/commons/*'],
removeDir: true,
swDestRoot: './public/workbox',
swURLRoot: '/workbox',
modifyUrlPrefix: {
'.next': '/_next',
},
runtimeCaching: [
{
urlPattern: '/',
handler: 'networkFirst',
options: {
cacheName: 'html-cache',
},
},
{
urlPattern: /.*\.(?:png|jpg|jpeg|svg|gif)/,
handler: 'cacheFirst',
options: {
cacheName: 'image-cache',
cacheableResponse: {
statuses: [0, 200],
},
},
},
],
};
if (!isServer && !dev) {
config.plugins.push(
new NextWorkboxPlugin({
distDir,
buildId,
importWorkboxFrom: 'cdn',
...workboxOptions,
}),
);
}
return config;
},
};