-
Notifications
You must be signed in to change notification settings - Fork 1
/
next.config.js
118 lines (103 loc) · 2.77 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
const withAntdLess = require("next-plugin-antd-less");
/** @type {import('next').NextConfig} */
const nextConfig = withAntdLess({
// https://nextjs.org/docs/advanced-features/output-file-tracing#automatically-copying-traced-files
output: 'standalone',
reactStrictMode: false,
/**
* From Static structure: /about.html
* To Static structure: /about/index.html
*
* But this also make all client url end with a `/`, so we will turn it off
* https://nextjs.org/docs/api-reference/next.config.js/exportPathMap#adding-a-trailing-slash
*/
// trailingSlash: false,
// images: { loader: "custom" },
images: {
loader: "imgix",
path: "",
},
// sassOptions: {
// includePaths: [path.join(__dirname, 'styles')],
// },
/**
* Custom webpack config
* https://nextjs.org/docs/api-reference/next.config.js/custom-webpack-config
*/
webpack: (config, { isServer }) => {
const rules = config.module.rules;
inject_git_commit_id_to_page(rules);
inject_app_env(rules);
return config;
},
});
function inject_git_commit_id_to_page(rules) {
/**
* Inject git commit id into debug page
*/
const git_commit_id = require("child_process")
.execSync("git rev-parse --short HEAD")
.toString()
.trim();
const stringReplaceLoaderRule = {
test: /pages\/lucis-debug\/index\.tsx$/,
loader: "string-replace-loader",
options: {
search: "LUCIS_VERSION_COMMIT_ID",
replace: git_commit_id,
},
};
rules.push(stringReplaceLoaderRule);
}
function inject_app_env(rules) {
const git_branch = require("child_process")
/**
* NOTE: You need to run in on Mac, Linux, or WSL, We prohibit Windows
*/
.execSync("cat .git/HEAD")
// .execSync('git branch --show-current')
.toString()
.trim();
let app_env = '';
if (git_branch === "ref: refs/heads/main") {
app_env = 'prod'
} else if (git_branch === "ref: refs/heads/beta") {
app_env = 'beta'
} else if (git_branch === "ref: refs/heads/test") {
app_env = 'stg'
} else {
app_env = 'dev'
}
rules.push({
test: /utils\/Env\.ts$/,
loader: "string-replace-loader",
options: {
search: '"APP_ENV"',
replace: `"${app_env}"`,
},
});
}
function show_testnet_text_on_header(rules) {
/**
* Show testnet text on the header
*/
const git_branch = require("child_process")
/**
* NOTE: You need to run in on Mac, Linux, or WSL, We prohibit Windows
*/
.execSync("cat .git/HEAD")
// .execSync('git branch --show-current')
.toString()
.trim();
rules.push({
test: /components\/ui\/header\/Header\.tsx$/,
loader: "string-replace-loader",
options: {
search: '"IS_TESTNET"',
replace: (git_branch === "ref: refs/heads/trial").toString(),
},
});
}
module.exports = {
...nextConfig
};