Browse Source

新增一键打包的脚本

ZaiZai 1 năm trước cách đây
mục cha
commit
c9704e355a
8 tập tin đã thay đổi với 95 bổ sung13 xóa
  1. 2 1
      package.json
  2. 46 0
      scripts/build.js
  3. 16 0
      scripts/restore.js
  4. 1 1
      src/App.vue
  5. 6 8
      src/config/index.js
  6. 9 0
      src/config/index.json
  7. 13 0
      src/config/index.md
  8. 2 3
      vite.config.js

+ 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.5",

+ 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)
 })
 
 //设置主题

+ 6 - 8
src/config/index.js

@@ -1,3 +1,5 @@
+import config from './index.json'
+
 //主要配置
 export default {
     title: '泓创智诚',
@@ -15,14 +17,10 @@ export default {
     tokenKey: 'client-access-token',
     refreshTokenKey: 'client-refresh-token',
     statusWhiteList: [],    //http的status默认放行列表
-    ossUrl: 'https://bladex-test-info.oss-cn-chengdu.aliyuncs.com', //oss地址
     isLog: 'auto',  //是否打印日志
-    smsPhone: '',  //测试接受短信验证码的手机号
-    dev_version: '202304111410',    //开发版本号
-    host: 'http://47.110.251.215:8090',  //测试线上
-    //host: 'http://127.0.0.1:8090',  //打包线上
-    //host: 'http://192.168.0.116:8090', //祝炜
-    //host: 'http://192.168.0.155', //刘依程
+    ...config,
+    ossUrl: 'https://bladex-test-info.oss-cn-chengdu.aliyuncs.com', //oss地址
     socket: 'wss://business.hcxxy.com/wss/websocket/',  //测试线上
-    //socket: 'ws://127.0.0.1:5399/websocket/',  //打包线上
+    //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"
+    }
+}

+ 13 - 0
src/config/index.md

@@ -0,0 +1,13 @@
+# 主要配置说明
+
+### version  开发版本号
+
+### target   请求地址,http://127.0.0.1:8090
+
+### smsPhone 测试的短信接收手机号
+
+### vite     vite配置
+
+### port     服务端口,5173
+
+### host     是否可局域网访问, 0.0.0.0

+ 2 - 3
vite.config.js

@@ -36,13 +36,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'), '/'),
             }
         }