Skip to content

Commit 4cd8e9a

Browse files
committed
[refactor] Improve environment variable handling in farm.config.ts
1 parent 070c49f commit 4cd8e9a

File tree

1 file changed

+34
-28
lines changed

1 file changed

+34
-28
lines changed

farm.config.ts

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,44 @@ import { defineConfig } from "@farmfe/core";
22
import farmPostcssPlugin from "@farmfe/js-plugin-postcss";
33
import path from "path";
44

5-
const env = {
6-
SD_BACKEND_URL: process.env.SD_BACKEND_URL,
7-
SD_CLIENT_ID: process.env.SD_CLIENT_ID,
8-
SD_AUTHORITY_URL: process.env.SD_AUTHORITY_URL,
9-
SD_REDIRECT_URL: process.env.SD_REDIRECT_URL,
10-
SD_LOGOUT_REDIRECT_URL: process.env.SD_LOGOUT_REDIRECT_URL,
11-
SD_AUTH_SECRET: process.env.SD_AUTH_SECRET,
12-
};
5+
export default defineConfig((cfg) => {
6+
let env: object | undefined;
137

14-
for (const [key, value] of Object.entries(env)) {
15-
if (!value) {
16-
throw new Error(`Environment variable ${key} is missing or empty.`);
17-
}
18-
}
8+
if (cfg.mode !== "development") {
9+
env = {
10+
SD_BACKEND_URL: process.env.SD_BACKEND_URL,
11+
SD_CLIENT_ID: process.env.SD_CLIENT_ID,
12+
SD_AUTHORITY_URL: process.env.SD_AUTHORITY_URL,
13+
SD_REDIRECT_URL: process.env.SD_REDIRECT_URL,
14+
SD_LOGOUT_REDIRECT_URL: process.env.SD_LOGOUT_REDIRECT_URL,
15+
SD_AUTH_SECRET: process.env.SD_AUTH_SECRET,
16+
};
1917

20-
export default defineConfig({
21-
plugins: ["@farmfe/plugin-react", farmPostcssPlugin()],
22-
compilation: {
23-
resolve: {
24-
alias: {
25-
"~/": path.join(process.cwd(), "src"),
18+
for (const [key, value] of Object.entries(env)) {
19+
if (!value) {
20+
throw new Error(`Environment variable ${key} is missing or empty.`);
2621
}
22+
}
23+
}
24+
25+
return {
26+
plugins: ["@farmfe/plugin-react", farmPostcssPlugin()],
27+
compilation: {
28+
resolve: {
29+
alias: {
30+
"~/": path.join(process.cwd(), "src"),
31+
}
32+
},
33+
define: env,
2734
},
28-
define: env,
29-
},
30-
envPrefix: "SD_",
31-
server: {
32-
proxy: {
33-
"/api": {
34-
target: "https://status.cloudmon.eco.tsi-dev.otc-service.com",
35-
changeOrigin: true
35+
envPrefix: "SD_",
36+
server: {
37+
proxy: {
38+
"/api": {
39+
target: "https://status.cloudmon.eco.tsi-dev.otc-service.com",
40+
changeOrigin: true
41+
}
3642
}
3743
}
38-
}
44+
};
3945
});

0 commit comments

Comments
 (0)