diff --git a/.gitignore b/.gitignore index 18515c4..2fb12a6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ .hbuilderx/ .history/ +env.js node_moudel/ package-lock.json unpackage/dist/build/.automator/ diff --git a/build/build.js b/build/build.js new file mode 100644 index 0000000..e69de29 diff --git a/build/env.config.js b/build/env.config.js new file mode 100644 index 0000000..031de36 --- /dev/null +++ b/build/env.config.js @@ -0,0 +1,45 @@ +/* + * @Author: ch + * @Date: 2022-05-05 14:40:00 + * @LastEditors: ch + * @LastEditTime: 2022-05-05 18:07:18 + * @Description: 根据git分支生成对应环境的环境变量 + * 开发时如果环境变量换了,可以不用重启服务,直接运行node env.config.js即可 + */ +const fs = require('fs'); +const path = require('path'); +const getRepoInfo = require('git-repo-info'); + +const envConfig = { + dev : { + base_url: 'dev' + }, + test : { + base_url: 'xxx' + }, + reslese : { + base_url: 'xxx' + }, + prod : { + base_url: 'xxx' + } +} +const branch = getRepoInfo().branch; // 调用获取git信息 +let curEnvConfig = {}; +switch (branch){ + case 'msb_test': + curEnvConfig = envConfig.test; + break; + case 'msb_beta': + curEnvConfig = envConfig.release; + break; + case 'msb_prod': + curEnvConfig = envConfig.prod; + break; + default: + curEnvConfig = envConfig.dev; + break; + +} +fs.writeFileSync(`${path.resolve(__dirname, '../common/config')}/env.js`, + `const ENV = ${JSON.stringify(curEnvConfig)}; export default ENV;`); diff --git a/common/utils/requset.js b/common/utils/requset.js index a0a3634..8c7cc6e 100644 --- a/common/utils/requset.js +++ b/common/utils/requset.js @@ -2,7 +2,7 @@ * @Author: ch * @Date: 2022-03-17 17:42:32 * @LastEditors: ch - * @LastEditTime: 2022-05-05 16:22:30 + * @LastEditTime: 2022-05-05 19:00:38 * @Description: 项目接口请求统一处理器,返回一个需要token和不需要token的请求封装方法 */ diff --git a/package.json b/package.json index 28370f4..a935eb2 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "vuex": "^3.6.2" }, "devDependencies": { - "@dcloudio/uni-helper-json": "^1.0.13" + "@dcloudio/uni-helper-json": "^1.0.13", + "git-repo-info": "^2.1.1" } } diff --git a/pages/index/components/Banner.vue b/pages/index/components/Banner.vue index 874cfea..1846115 100644 --- a/pages/index/components/Banner.vue +++ b/pages/index/components/Banner.vue @@ -2,7 +2,7 @@ * @Author: ch * @Date: 2022-03-23 10:31:12 * @LastEditors: ch - * @LastEditTime: 2022-04-30 19:30:49 + * @LastEditTime: 2022-05-05 18:37:20 * @Description: file content -->