chore: 使用宏来控制自定义H5网站部署发布

This commit is contained in:
2025-12-25 17:00:10 +08:00
parent 0e60dd7d0f
commit 2c3786546c
3 changed files with 73 additions and 6 deletions

View File

@@ -17,13 +17,32 @@ try {
// #endif
// 线上版本部署域名, 注意: 必须以 '/' 结尾,适用于小程序/H5/快应用等场景
// const defaultDomain = 'https://5g.aigc-quickapp.com/'; // 部署H5站点时需要配置为当前站点域名
const defaultDomain = 'https://xcx.aigc-quickapp.com/'; // 部署H5站点时需要配置为当前站点域名
// 默认域名, 自定义发行时可以修改
let defaultDomain = '';
// #ifdef H5_XCX_AIGC_QUICKAPP_COM
defaultDomain = 'https://xcx.aigc-quickapp.com/';
// #endif
// #ifdef H5_5G_AIGC_QUICKAPP_COM
defaultDomain = 'https://5g.aigc-quickapp.com/';
// #endif
// #ifdef H5_TEST_AIGC_QUICKAPP_COM
defaultDomain = 'https://test.aigc-quickapp.com/';
// #endif
// 确保域名以 '/' 结尾
if (defaultDomain && !defaultDomain.endsWith('/')) {
defaultDomain += '/';
}
// 本地调试配置示例文件
// 复制.local.config.js.example 并重命名为 .local.config.js 以使用自定义本地配置
let localDevConfig = { uniacid: 0, domain: defaultDomain };
// #ifndef PRODUCTION
// 尝试动态加载本地配置文件
// 注意:在发行模式下,.local.config.js 不会被打包,因此会自动使用默认配置
try {
// 尝试从项目根目录加载本地配置文件
// 使用相对路径的方式,确保在不同平台下都能正确解析
@@ -34,10 +53,11 @@ try {
} catch (e) {
// 如果本地配置文件不存在或加载失败,保持使用默认配置
// 只在开发模式下输出提示信息
// #ifndef APP-PLUS || MP-WEIXIN || MP-ALIPAY || MP-BAIDU || MP-QQ || MP-TOUTIAO
// #ifdef WEB
console.log('本地配置文件 .local.config.js 不存在,使用默认配置');
// #endif
}
// #endif
const { uniacid = 0, domain = defaultDomain } = localDevConfig ?? { uniacid: 0, domain: defaultDomain }

View File

@@ -108,7 +108,7 @@
},
"optimization" : {
"treeShaking" : {
"enable" : false
"enable" : true
}
},
"domain" : " ",

View File

@@ -7,5 +7,52 @@
},
"dependencies": {
"jweixin-module": "^1.6.0"
},
"uni-app": {
"scripts": {
"weixin": {
"title": "微信小程序自定义发行",
"env": {
"UNI_PLATFORM": "mp-weixin"
},
"define": {
"MP_WEIXIN": true,
"PRODUCTION": true
}
},
"h5-xcx.aigc-quickapp.com": {
"title": "H5-xcx.aigc-quickapp.com",
"env": {
"UNI_PLATFORM": "h5"
},
"define": {
"H5_XCX_AIGC_QUICKAPP_COM": true,
"H5_PRODUCTION": true,
"PRODUCTION": true
}
},
"h5-5g.aigc-quickapp.com": {
"title": "H5-5g.aigc-quickapp.com",
"env": {
"UNI_PLATFORM": "h5"
},
"define": {
"H5_5G_AIGC_QUICKAPP_COM": true,
"H5_PRODUCTION": true,
"PRODUCTION": true
}
},
"h5-test.aigc-quickapp.com": {
"title": "H5-test.aigc-quickapp.com",
"env": {
"UNI_PLATFORM": "h5"
},
"define": {
"H5_TEST_AIGC_QUICKAPP_COM": true,
"H5_PRODUCTION": true,
"PRODUCTION": true
}
}
}
}
}