diff --git a/compile_dev.sh b/compile_dev.sh index 22b2adc..bd0d930 100755 --- a/compile_dev.sh +++ b/compile_dev.sh @@ -14,6 +14,21 @@ echo "Build process started at $(date)" | tee $LOGFILE # 获取当前分支名 current_branch=$(git rev-parse --abbrev-ref HEAD) +# 指定并加载环境变量文件(dev 使用 .env.development) +ENV_FILE=".env.development" +if [ -f "$ENV_FILE" ]; then + echo "Loading environment from $ENV_FILE" | tee -a $LOGFILE + set -a + # shellcheck disable=SC1090 + source "$ENV_FILE" + set +a +else + echo "未找到 $ENV_FILE,继续使用当前环境变量" | tee -a $LOGFILE +fi + +# 设置 NODE_ENV 为 development,避免默认使用 production +export NODE_ENV="development" + # 打包之前,需要检查是否在 dev 分支,工作区是否干净,是否和远程分支一致 if [ "$(git branch --show-current)" != "$BRANCH_NAME" ]; then echo "当前分支不是 dev 分支" diff --git a/compile_prod.sh b/compile_prod.sh index b0b23a1..9c947d6 100755 --- a/compile_prod.sh +++ b/compile_prod.sh @@ -14,6 +14,21 @@ echo "Build process started at $(date)" | tee $LOGFILE # 获取当前分支名 current_branch=$(git rev-parse --abbrev-ref HEAD) +# 指定并加载环境变量文件(prod 使用 .env.production) +ENV_FILE=".env.production" +if [ -f "$ENV_FILE" ]; then + echo "Loading environment from $ENV_FILE" | tee -a $LOGFILE + set -a + # shellcheck disable=SC1090 + source "$ENV_FILE" + set +a +else + echo "未找到 $ENV_FILE,继续使用当前环境变量" | tee -a $LOGFILE +fi + +# 设置 NODE_ENV 为 production +export NODE_ENV="production" + # 打包之前,需要检查是否在 prod 分支,工作区是否干净,是否和远程分支一致 if [ "$(git branch --show-current)" != "$BRANCH_NAME" ]; then echo "当前分支不是 prod 分支" diff --git a/lib/store/serverSettingHooks.ts b/lib/store/serverSettingHooks.ts index 0245d19..3560aae 100644 --- a/lib/store/serverSettingHooks.ts +++ b/lib/store/serverSettingHooks.ts @@ -17,7 +17,7 @@ export function useServerSetting(code: string, defaultValue?: T) { dispatch(setLoading({ code, loading: true })); try { const value = await fetchSettingByCode(code, defaultValue as T | undefined); - dispatch(setValue({ code, value: value as T })); + dispatch(setValue({ code, value: value })); } catch (e: any) { dispatch(setError({ code, error: e?.message || 'Load failed' })); } diff --git a/lib/store/serverSettingSlice.ts b/lib/store/serverSettingSlice.ts index e90ecaa..bce690f 100644 --- a/lib/store/serverSettingSlice.ts +++ b/lib/store/serverSettingSlice.ts @@ -27,7 +27,7 @@ export const serverSettingSlice = createSlice({ const current = state.byCode[code] || {}; state.byCode[code] = { ...current, loading, error: loading ? undefined : current.error }; }, - setValue(state, action: PayloadAction<{ code: string; value: T }>) { + setValue(state, action: PayloadAction<{ code: string; value: any }>) { const { code, value } = action.payload as { code: string; value: unknown }; const current = state.byCode[code] || {}; state.byCode[code] = { ...current, loading: false, error: undefined, value };