Selaa lähdekoodia

更改为一键打包脚本

ZaiZai 2 vuotta sitten
vanhempi
commit
2d1f1097bf
9 muutettua tiedostoa jossa 593 lisäystä ja 396 poistoa
  1. 2 1
      package.json
  2. 46 0
      scripts/build.js
  3. 16 0
      scripts/restore.js
  4. 1 1
      src/App.vue
  5. 9 7
      src/config/index.js
  6. 9 0
      src/config/index.json
  7. 19 0
      src/config/index.md
  8. 2 3
      vite.config.js
  9. 489 384
      yarn.lock

+ 2 - 1
package.json

@@ -4,7 +4,8 @@
     "version": "3.5.0",
     "scripts": {
         "dev": "vite",
-        "build": "vite build"
+        "build": "vite build",
+        "node:build": "node ./scripts/build.js && vite build && node ./scripts/restore.js"
     },
     "dependencies": {
         "axios": "^1.3.4",

+ 46 - 0
scripts/build.js

@@ -0,0 +1,46 @@
+const path = require('path');
+const fs = require('fs');
+
+// 获取当前命令行上下文路径
+const currentDirectory = process.cwd();
+
+// 获取配置文件
+const indexJsonPath = path.join(currentDirectory, 'src/config/index.json');
+const indexJsonContent = fs.readFileSync(indexJsonPath, 'utf8');
+
+//创建缓存文件
+const cacheJsonPath = path.join(currentDirectory, 'scripts/cache.json');
+fs.writeFileSync(cacheJsonPath, indexJsonContent, 'utf8');
+
+//修改配置文件
+const indexJson = JSON.parse(indexJsonContent);
+indexJson.version = dateFormat(new Date());         //版本号
+indexJson.target = "http://127.0.0.1:8090";         //接口地址
+indexJson.smsPhone = "";                            //短信接口手机号
+indexJson.vite = {};                                //vite配置
+
+//更新配置文件
+fs.writeFileSync(indexJsonPath, JSON.stringify(indexJson, null, 2));
+
+//时间格式化
+function dateFormat(date) {
+    let format = 'yyyyMMddhhmmss';
+    let o = {
+        "M+": date.getMonth() + 1, //month
+        "d+": date.getDate(), //day
+        "h+": date.getHours(), //hour
+        "m+": date.getMinutes(), //minute
+        "s+": date.getSeconds(), //second
+        "q+": Math.floor((date.getMonth() + 3) / 3), //quarter
+        "S": date.getMilliseconds() //millisecond
+    }
+    if (/(y+)/.test(format)) {
+        format = format.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
+    }
+    for (let k in o) {
+        if (new RegExp("(" + k + ")").test(format)) {
+            format = format.replace(RegExp.$1, RegExp.$1.length === 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
+        }
+    }
+    return format;
+}

+ 16 - 0
scripts/restore.js

@@ -0,0 +1,16 @@
+const path = require('path');
+const fs = require('fs');
+
+// 获取当前命令行上下文路径
+const currentDirectory = process.cwd();
+
+// 获取缓存文件
+const cacheJsonPath = path.join(currentDirectory, 'scripts/cache.json');
+const cacheJsonContent = fs.readFileSync(cacheJsonPath, 'utf8');
+
+// 恢复配置文件
+const indexJsonPath = path.join(currentDirectory, 'src/config/index.json');
+fs.writeFileSync(indexJsonPath, cacheJsonContent, 'utf8');
+
+// 删除缓存文件
+fs.unlinkSync(cacheJsonPath);

+ 1 - 1
src/App.vue

@@ -28,7 +28,7 @@ watch(() => [
 
 nextTick(()=> {
     setUserTheme(appStore.getThemeVal, appStore.getColor)
-    ulog('客户端 启动成功', '当前开发版本 v' + config?.dev_version)
+    ulog('客户端 启动成功', '当前开发版本 v' + config?.version)
 })
 
 //设置主题

+ 9 - 7
src/config/index.js

@@ -1,3 +1,4 @@
+import config from './index.json'
 //主要配置
 export default {
     title: '档案管理 泓创智诚',
@@ -15,12 +16,13 @@ export default {
     tokenKey: 'archives-access-token',
     refreshTokenKey: 'archives-refresh-token',
     statusWhiteList: [],    //http的status默认放行列表
-    ossUrl: 'https://bladex-test-info.oss-cn-chengdu.aliyuncs.com', //oss地址
-    smsPhone: '',  //测试接受短信验证码的手机号
     role_id: "1610526744728031234",  //档案总管理角色组ID
-    dev_version: '202303211105',    //开发版本号
-    host: 'http://47.110.251.215:8090',  //测试线上
-    //host: 'http://127.0.0.1:8090',  //打包线上
-    //host: 'http://192.168.0.118', //祝炜
-    //host: 'http://192.168.0.155', //刘依程
+    ...config,
+    ossUrl: 'https://bladex-chongqing-info.oss-cn-hangzhou.aliyuncs.com', //oss地址
+
+    //这里不再支持配置请求地址,请在 src/config/index.json 文件中配置。
+    //相关参数,可查阅 src/config/index.md 文件说明
+
+    //target: 'http://47.110.251.215:8090',  //测试线上
+    //target: 'http://127.0.0.1:8090',  //打包线上
 }

+ 9 - 0
src/config/index.json

@@ -0,0 +1,9 @@
+{
+    "version": "202304141558",
+    "target": "http://47.110.251.215:8090",
+    "smsPhone": "",
+    "vite": {
+        "port": 5173,
+        "host": "0.0.0.0"
+    }
+}

+ 19 - 0
src/config/index.md

@@ -0,0 +1,19 @@
+# 主要配置说明
+
+### version  开发版本号
+
+### target   请求地址,http://127.0.0.1:8090
+
+### smsPhone 测试的短信接收手机号
+
+### vite     vite配置
+
+### port     服务端口,5173
+
+### host     是否可局域网访问, 0.0.0.0
+
+
+## index.json 里的配置,可随意修改,再编译打包的时候,会自动修改为线上的相关参数。
+## 主要用于一键打包编译,但不支持 npm,如果是使用的npm,请在打包的时候,删除 yarn.lock 文件,为了统一,建议大家,都使用 yarn 命令。
+## 如果不需要打包,只是本地调试开发,可无视 npm 或 yarn 的使用。
+## package.json 文件中的 node:build 命令,就是一键编译打包的命令。

+ 2 - 3
vite.config.js

@@ -37,13 +37,12 @@ export default defineConfig({
         }),
     ],
     server: {
-        //port: '3001',
-        //host: '0.0.0.0',
+        ...config.vite,
         proxy: {
             '/api': {
                 ws: true,
                 changeOrigin: true,
-                target: config.host,
+                target: config.target,
                 rewrite: (path) => path.replace(new RegExp('^/api'), '/'),
             }
         }

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 489 - 384
yarn.lock


Kaikkia tiedostoja ei voida näyttää, sillä liian monta tiedostoa muuttui tässä diffissä