forked from Crossbell-Box/xLog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
next.config.js
117 lines (109 loc) · 3.15 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
// @ts-check
const pkg = require("./package.json")
const spawn = require("cross-spawn")
const withBundleAnalyzer = require("@next/bundle-analyzer")({
enabled: process.env.ANALYZE === "true",
})
const execSync = require("child_process").execSync
const { i18n } = require("./next-i18next.config")
const cache = require("next-pwa/cache")
const withPWA = require("next-pwa")({
disable: process.env.NODE_ENV === "development",
dest: "public",
publicExcludes: ["*"],
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],
},
},
},
{
urlPattern: /\/_next\/image\?url=.+%2Fipfs%2F([^/?#]+)$/i,
handler: "CacheFirst",
options: {
cacheName: "next-ipfs",
expiration: {
maxEntries: 64,
maxAgeSeconds: 365 * 24 * 60 * 60, // 365 days
},
},
},
// @ts-ignore
...cache,
],
})
const lastCommitCommand = "git rev-parse HEAD"
class UnoCSS {
/**
*
* @param {import('webpack').Compiler} compiler
*/
apply(compiler) {
compiler.hooks.beforeRun.tapPromise("unocss", async () => {
if (globalThis.uno_built) return
globalThis.uno_watching = true
spawn.sync("pnpm", ["uno-generate"], { stdio: "inherit" })
})
compiler.hooks.watchRun.tap("unocss", () => {
if (globalThis.uno_watching) return
globalThis.uno_watching = true
spawn("pnpm", ["uno-generate", "--watch"], { stdio: "inherit" })
})
}
}
/** @type {import('next').NextConfig} */
module.exports = withBundleAnalyzer(
// @ts-ignore
withPWA({
env: {
APP_DESCRIPTION: pkg.description,
},
experimental: {
scrollRestoration: true,
},
output: "standalone",
productionBrowserSourceMaps: true,
webpack(config) {
config.plugins.push(new UnoCSS())
return config
},
images: {
dangerouslyAllowSVG: true,
contentSecurityPolicy:
"default-src 'self'; script-src 'none'; sandbox; style-src 'unsafe-inline';",
remotePatterns: [{ hostname: "**" }],
},
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,
OPENAI_API_KEY: process.env.OPENAI_API_KEY,
},
}),
)