forked from Crossbell-Box/xLog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnext.config.js
138 lines (126 loc) · 4.23 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
// @ts-check
const pkg = require("./package.json")
const withBundleAnalyzer = require("@next/bundle-analyzer")({
enabled: process.env.ANALYZE === "true",
})
const execSync = require("child_process").execSync
const withPWA = require("@ducanh2912/next-pwa").default({
disable: process.env.NODE_ENV === "development",
dest: "public",
publicExcludes: ["*"],
buildExcludes: [
/\.map$/,
/^manifest.*\.js$/,
/^\/_next\/static\/chunks\/app\/dashboard/,
],
extendDefaultRuntimeCaching: true,
workboxOptions: {
runtimeCaching: [
{
urlPattern: ({ request }) => {
return request.headers.get("x-middleware-prefetch")
},
handler: "NetworkOnly",
},
{
urlPattern: ({ url }) => {
return /\/ipfs\/([^/?#]+)$/.test(url.toString())
},
handler: "CacheFirst",
options: {
cacheName: "next-ipfs",
expiration: {
maxEntries: 64,
maxAgeSeconds: 365 * 24 * 60 * 60, // 365 days
},
cacheableResponse: {
statuses: [0, 200],
},
},
},
{
// cspell:ignore Fipfs
urlPattern: /\/_next\/image\?url=.+%2Fipfs%2F([^/?#]+)$/i,
handler: "CacheFirst",
options: {
cacheName: "next-ipfs",
expiration: {
maxEntries: 64,
maxAgeSeconds: 365 * 24 * 60 * 60, // 365 days
},
},
},
],
},
})
const lastCommitCommand = "git rev-parse HEAD"
/** @type {import('next').NextConfig} */
module.exports = withBundleAnalyzer(
// @ts-ignore
withPWA({
env: {
APP_DESCRIPTION: pkg.description,
},
experimental: {
scrollRestoration: true,
appDir: true,
serverComponentsExternalPackages: ["rehype-react"],
},
output: "standalone",
productionBrowserSourceMaps: true,
webpack(config) {
config.resolve.fallback = { fs: false } // polyfill node-id3
// https://github.com/WalletConnect/walletconnect-monorepo/blob/7716e164281c2f531145d682c3658f761fa0a823/providers/universal-provider/src/utils/deepLinks.ts#L39
// @walletconnect/universal-provider imports react-native conditionally.
// Since this is a NextJS app, simply mark it as external to avoid the webpack bundling warning.
config.externals.push("react-native")
// https://github.com/WalletConnect/walletconnect-utils/blob/b7d7dc003c25dd33ef74c2fac483140f71a51d86/jsonrpc/http-connection/src/http.ts#L2
// `@walletconnect/jsonrpc-http-connection` imports `cross-fetch` to support fetch in Node.js. It's unnecessary for Next.JS app.
config.resolve.alias["cross-fetch"] = require.resolve(
"next/dist/build/polyfills/fetch/index.js",
)
// https://github.com/kkomelin/isomorphic-dompurify/issues/54
// Fix isomorphic-dompurify in app router
config.externals = [...config.externals, "canvas", "jsdom", "sharp"]
return config
},
images: {
dangerouslyAllowSVG: true,
contentSecurityPolicy:
"default-src 'self'; script-src 'none'; sandbox; style-src 'unsafe-inline';",
remotePatterns: [
{ hostname: "**" },
{ protocol: "https", hostname: "pbs.twimg.com" },
{ protocol: "https", hostname: "abs.twimg.com" },
],
},
async generateBuildId() {
return execSync(lastCommitCommand).toString().trim()
},
serverRuntimeConfig: {
ENV_REDIS_URL: process.env.REDIS_URL,
ENV_REDIS_EXPIRE: process.env.REDIS_EXPIRE,
ENV_REDIS_REFRESH: process.env.REDIS_REFRESH,
ENV_MORALIS_WEB3_API_KEY: process.env.MORALIS_WEB3_API_KEY,
ENV_ALCHEMY_ETHEREUM_API_KEY: process.env.ALCHEMY_ETHEREUM_API_KEY,
ENV_ALCHEMY_POLYGON_API_KEY: process.env.ALCHEMY_POLYGON_API_KEY,
ENV_NFTSCAN_API_KEY: process.env.NFTSCAN_API_KEY,
ENV_OPENSEA_API_KEY: process.env.OPENSEA_API_KEY,
ENV_POAP_API_KEY: process.env.POAP_API_KEY,
ENV_OPENAI_API_KEY: process.env.OPENAI_API_KEY,
},
async headers() {
return [
{
source: "/.well-known/apple-app-site-association",
headers: [
{
key: "Content-Type",
value: "application/json",
},
],
},
]
},
}),
)