diff --git a/docusaurus.config.js b/docusaurus.config.js index 85d95cf..fc70a5a 100644 --- a/docusaurus.config.js +++ b/docusaurus.config.js @@ -1,6 +1,7 @@ // @ts-check -const PREVIEW = process.env.PREVIEW ?? "false"; +// REGION can be either "cn" or "global" +const REGION = process.env.REGION || "cn"; /** @type {import('@docusaurus/types').Config} */ const config = { @@ -167,7 +168,24 @@ const config = { }, }), - plugins: ["docusaurus-plugin-sass"], + plugins: [ + "docusaurus-plugin-sass", + function envDefinePlugin() { + return { + name: "env-define-plugin", + configureWebpack() { + const webpack = require("webpack"); + return { + plugins: [ + new webpack.DefinePlugin({ + "process.env.REGION": JSON.stringify(REGION), + }), + ], + }; + }, + }; + }, + ], }; module.exports = config; diff --git a/src/constants/env.ts b/src/constants/env.ts index ef24d4d..65ebd3e 100644 --- a/src/constants/env.ts +++ b/src/constants/env.ts @@ -1,5 +1,5 @@ export const BRAND: string = "leancloud"; -export const REGION: string = "cn"; +export const REGION: string = process.env.REGION || "cn"; // Cloud Engine export const CLI_BINARY: string = BRAND === "tds" ? "tds" : "lean";