-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnext.config.js
79 lines (71 loc) · 1.88 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
const nextPwa = require("next-pwa")
const uriJs = require("uri-js")
const runtimeCache = require("./src/configurations/serviceWorkerRuntimeCache")
let commitHash
try {
commitHash = require("child_process")
.execSync("git rev-parse --short HEAD")
.toString().trim() || "unknown"
} catch (e) {
commitHash = "unknown"
}
let versionString
try {
const YAML = require("yaml")
const fs = require("fs")
const changelog = YAML.parse(fs.readFileSync("./changelog.yaml", "utf8"))
const version = changelog.versions[0].version
versionString = version.join(".")
} catch (e) {
versionString = "unknown"
}
const withPWA = nextPwa({
dest: "public",
disable: process.env.NODE_ENV === "development",
register: false,
skipWaiting: true,
sw: `sw-${commitHash}.js`,
runtimeCaching: runtimeCache
})
const nextConfig = {
compress: false,
images: {
deviceSizes: [640, 750, 828, 1080],
domains: [process.env.THERESA_STATIC || "static.theresa.wiki"],
imageSizes: [128, 256, 384],
unoptimized: true,
},
poweredByHeader: false,
reactStrictMode: true,
output: "standalone",
generateBuildId: async () => {
return commitHash
},
async rewrites() {
return [
{
source: "/:server(CN|US|JP|TW|KR)/:path*",
destination: "/:path*?server=:server"
}
]
},
webpack: (config, { buildId, dev, isServer, defaultLoaders, webpack }) => {
config.module.rules.push({
test: /\.md$/i,
loader: "raw-loader",
})
config.module.rules.push({
test: /\.ya?ml$/,
use: "yaml-loader"
})
return config
},
publicRuntimeConfig: {
THERESA_WIKI_VERSION: versionString,
GIT_COMMIT: commitHash,
GTAG_ID: process.env.GTAG_ID,
THERESA_STATIC: uriJs.parse(process.env.THERESA_STATIC || "https://static.theresa.wiki"),
CRISP_WEBSITE_ID: process.env.CRISP_WEBSITE_ID,
}
}
module.exports = withPWA(nextConfig)