-
Notifications
You must be signed in to change notification settings - Fork 0
/
next.config.js
41 lines (34 loc) · 1.18 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
const fs = require("fs");
const { env } = require("process");
const { version } = require("./package.json");
const { PHASE_PRODUCTION_SERVER } = require("next/constants");
const CONFIG_ENV_VAR_NAME = "RPC_CONFIG";
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
output: "standalone"
};
module.exports = (phase) => {
const isProduction = phase === PHASE_PRODUCTION_SERVER;
const configJson = env[CONFIG_ENV_VAR_NAME];
const hasConfig = Boolean(configJson);
const saveConfigFile = isProduction && hasConfig;
const mode = isProduction ? "production" : "development";
const configInfo = hasConfig
? `Config env variable '${CONFIG_ENV_VAR_NAME}' exists.`
: `No value found for config env variable '${CONFIG_ENV_VAR_NAME}'. Skipping writing config file.`;
console.log(
`Initializing app version '${version}' in '${mode}' mode. ${configInfo}`
);
if (saveConfigFile) {
saveConfig(config);
}
return nextConfig;
};
function saveConfig() {
console.log(
`Saving config file from '${CONFIG_ENV_VAR_NAME}' env variable value`
);
const configJson = env[CONFIG_ENV_VAR_NAME];
fs.writeFileSync("./data/config.json", configJson);
}