-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnext.config.js
executable file
·102 lines (99 loc) · 3.06 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
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
const withSass = require("@zeit/next-sass");
const withFonts = require("next-fonts");
const withOffline = require("next-offline");
const path = require("path");
const NextWorkboxPlugin = require("next-workbox-webpack-plugin");
const TsconfigPathsPlugin = require("tsconfig-paths-webpack-plugin");
const withTypescript = require("@zeit/next-typescript");
module.exports = withTypescript({
webpack(config, options) {
return config;
},
});
module.exports = (phase, nextConfig = {}) =>
withSass(
withFonts(
withOffline({
devSwSrc: "/public/service-worker.js",
webpack: (config, { isServer, buildId, dev, defaultLoaders }) => {
const workboxOptions = {
swDest: "/public/workbox/sw.js",
clientsClaim: true,
skipWaiting: true,
globPatterns: [".next/public/*", ".next/public/commons/*"],
modifyUrlPrefix: {
".next": "/_next",
},
runtimeCaching: [
{
urlPattern: "/",
handler: "networkFirst",
options: {
cacheName: "html-cache",
},
},
{
urlPattern: /[^3]\/rooms\//,
handler: "networkFirst",
options: {
cacheName: "html-cache",
},
},
{
urlPattern: new RegExp("TODO ADD URL"),
handler: "staleWhileRevalidate",
options: {
cacheName: "api-cache",
expiration: {
maxEntries: 150,
maxAgeSeconds: 24 * 60 * 60, // 1 day
},
cacheableResponse: {
statuses: [200],
},
},
},
{
urlPattern: /.*\.(?:png|jpg|jpeg|svg|gif)/,
handler: "cacheFirst",
options: {
cacheName: "image-cache",
cacheableResponse: {
statuses: [0, 200],
},
},
},
],
};
config.resolve.alias = {
...(config.resolve.alias || {}),
};
if (!isServer) {
config.plugins.push(
new NextWorkboxPlugin({
buildId,
...workboxOptions,
}),
);
}
config.module.rules.push({
test: /.svg$/,
use: ["@svgr/webpack"],
});
config.module.rules = config.module.rules.map(rule => {
if (rule.loader === "babel-loader") {
rule.options.cacheDirectory = false;
}
return rule;
});
if (config.resolve.plugins) {
config.resolve.plugins.push(new TsconfigPathsPlugin());
} else {
config.resolve.plugins = [new TsconfigPathsPlugin()];
}
return config;
},
target: "serverless",
}),
),
);