forked from gxwebsoft/mp-10550
改造env环境机制
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
// 租户ID
|
||||
export const TenantId = 10550;
|
||||
// 接口地址
|
||||
export const BaseUrl = 'https://cms-api.websoft.top/api';
|
||||
import { API_BASE_URL } from './env'
|
||||
|
||||
// 租户ID - 请根据实际情况修改
|
||||
export const TenantId = 'YOUR_TENANT_ID';
|
||||
// 接口地址 - 请根据实际情况修改
|
||||
export const BaseUrl = API_BASE_URL;
|
||||
// 当前版本
|
||||
export const Version = 'v3.0.8';
|
||||
// 版权信息
|
||||
|
||||
42
config/env.ts
Normal file
42
config/env.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
// 环境变量配置
|
||||
export const ENV_CONFIG = {
|
||||
// 开发环境
|
||||
development: {
|
||||
API_BASE_URL: 'http://localhost:9200/api',
|
||||
APP_NAME: 'Taro App Dev',
|
||||
DEBUG: 'true',
|
||||
},
|
||||
// 生产环境
|
||||
production: {
|
||||
API_BASE_URL: 'https://cms-api.websoft.top/api',
|
||||
APP_NAME: 'Taro App',
|
||||
DEBUG: 'false',
|
||||
},
|
||||
// 测试环境
|
||||
test: {
|
||||
API_BASE_URL: 'https://test-api.example.com/api',
|
||||
APP_NAME: 'Taro App Test',
|
||||
DEBUG: 'true',
|
||||
}
|
||||
}
|
||||
|
||||
// 获取当前环境配置
|
||||
export function getEnvConfig() {
|
||||
const env = process.env.NODE_ENV || 'development'
|
||||
if (env === 'production') {
|
||||
return ENV_CONFIG.production
|
||||
} else { // @ts-ignore
|
||||
if (env === 'test') {
|
||||
return ENV_CONFIG.test
|
||||
} else {
|
||||
return ENV_CONFIG.development
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 导出环境变量
|
||||
export const {
|
||||
API_BASE_URL,
|
||||
APP_NAME,
|
||||
DEBUG
|
||||
} = getEnvConfig()
|
||||
@@ -2,6 +2,7 @@ import { defineConfig, type UserConfigExport } from '@tarojs/cli'
|
||||
import TsconfigPathsPlugin from 'tsconfig-paths-webpack-plugin'
|
||||
import devConfig from './dev'
|
||||
import prodConfig from './prod'
|
||||
import { getEnvConfig } from './env'
|
||||
|
||||
// import vitePluginImp from 'vite-plugin-imp'
|
||||
// https://taro-docs.jd.com/docs/next/config#defineconfig-辅助函数
|
||||
@@ -28,6 +29,9 @@ export default defineConfig<'webpack5'>(async (merge, {}) => {
|
||||
sourceRoot: 'src',
|
||||
outputRoot: 'dist',
|
||||
defineConstants: {
|
||||
API_BASE_URL: JSON.stringify(getEnvConfig().API_BASE_URL),
|
||||
APP_NAME: JSON.stringify(getEnvConfig().APP_NAME),
|
||||
DEBUG: JSON.stringify(getEnvConfig().DEBUG)
|
||||
},
|
||||
copy: {
|
||||
patterns: [
|
||||
|
||||
Reference in New Issue
Block a user