-
Notifications
You must be signed in to change notification settings - Fork 0
/
next.config.js
53 lines (48 loc) · 1.25 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
// @ts-check
const { default: nextPWA } = require("@ducanh2912/next-pwa");
/**
* @import { RouteMatchCallbackOptions } from "workbox-core";
*/
/**
* @param {RouteMatchCallbackOptions} options
*/
function getGraphQLOperationName({ url }) {
if (url.pathname !== "/graphql") return null;
return url.searchParams.get("operationName");
}
/**
* @param {RouteMatchCallbackOptions} options
*/
function isGraphqlGetCurrentUser(options) {
return getGraphQLOperationName(options) === "GetCurrentUser";
}
/**
* @param {RouteMatchCallbackOptions} options
*/
function isGraphqlGet(options) {
return !!getGraphQLOperationName(options) && options.request.method === "GET";
}
module.exports = nextPWA({
dest: "public",
disable: process.env.NODE_ENV !== "production",
cacheOnFrontEndNav: true,
extendDefaultRuntimeCaching: true,
workboxOptions: {
runtimeCaching: [
{ urlPattern: isGraphqlGetCurrentUser, handler: "NetworkOnly" },
{ urlPattern: isGraphqlGet, handler: "NetworkFirst" },
],
},
})({
reactStrictMode: true,
webpack(config) {
config.module.rules.push({
test: /\.graphql$/,
loader: "@nitrogql/graphql-loader",
options: {
configFile: "./graphql.config.yaml",
},
});
return config;
},
});