-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathnext.config.ts
More file actions
69 lines (57 loc) · 2.16 KB
/
Copy pathnext.config.ts
File metadata and controls
69 lines (57 loc) · 2.16 KB
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
import JSON5 from "json5";
import type { NextConfig } from "next";
import {
PHASE_DEVELOPMENT_SERVER,
PHASE_PRODUCTION_BUILD,
} from "next/constants";
export default async function (phase: string): Promise<NextConfig> {
const nextConfig: NextConfig = {
eslint: {
ignoreDuringBuilds: true,
},
// See also alternative with patch-package:
// https://stackoverflow.com/a/77722836/1839099
serverExternalPackages: ["pdf-parse"],
experimental: {},
webpack: (config, { buildId, dev, isServer, defaultLoaders, webpack }) => {
// https://stackoverflow.com/questions/64926174/module-not-found-cant-resolve-fs-in-next-js-application
// ./node_modules/nlopt-js/dist/index.js; Module not found: Can't resolve 'fs'
config.resolve.fallback = { fs: false };
config.module.rules.push({
test: /\.json5$/i,
type: "json", // emit as JSON module
parser: { parse: JSON5.parse },
});
config.module.rules.push({
test: /\.svg$/,
use: ["@svgr/webpack"],
});
config.module.rules.push({
test: /\.ya?ml$/,
type: "json", // Required by Webpack v4
use: "yaml-loader",
});
return config;
},
};
if (phase === PHASE_DEVELOPMENT_SERVER || phase === PHASE_PRODUCTION_BUILD) {
const withSerwist = (await import("@serwist/next")).default({
// https://serwist.pages.dev/docs/next/configuring/cache-on-navigation
cacheOnNavigation: true,
// Note: This is only an example. If you use Pages Router,
// use something else that works, such as "service-worker/index.ts".
swSrc: "src/app/sw.ts",
swDest: "public/sw.js",
// reloadOnOnline: true,
disable: process.env.NODE_ENV === "development", // to disable pwa in development
// https://serwist.pages.dev/docs/next/configuring/reload-on-online
// Hopefully fixes issue where app reloads after phone lock/unlock on Android Chrome.
reloadOnOnline: false,
// Handled in src/serwistStuff.tsx
// https://serwist.pages.dev/docs/next/configuring/register
register: false,
});
return withSerwist(nextConfig);
}
return nextConfig;
}