Browse Source

更新打包方式

ZaiZai 1 year ago
parent
commit
d1eff563bb
4 changed files with 56 additions and 10 deletions
  1. 18 0
      README.md
  2. 1 6
      package.json
  3. 9 4
      scripts/build.js
  4. 28 0
      scripts/public.js

+ 18 - 0
README.md

@@ -62,3 +62,21 @@ js-fast-way 文档
 - **[文档地址](https://js-fast-way.vercel.app/)**
 - **[国内文档地址](http://izaizaiaa.gitee.io/js-fast-way)**
 
+---
+
+### 打包说明
+
+#### 一键全打包
+
+`node:build` 为一键打包为zip的方式
+
+
+#### 缺省打包
+
+`build:nopublic` 为不包含`/public/plugins`文件夹的打包方式,减少每次打包后的体积过大的问题。
+
+但是如果此相关文件有变动,需要使用 `node:build` 方式打包
+
+一般来说,`/public/plugins` 很少出现变动的情况。
+
+在服务器上更新时,请注意,不要删除服务器上存在的 `plugins`,否则会出现异常。

+ 1 - 6
package.json

@@ -6,12 +6,7 @@
         "dev": "vite",
         "build": "vite build",
         "node:build": "node ./scripts/build.js && vite build && node ./scripts/restore.js && node ./scripts/zip.js",
-        "yarn:link": "yarn link hc-vue3-ui",
-        "npm:link": "npm link hc-vue3-ui",
-        "yarn:unlink": "yarn unlink hc-vue3-ui",
-        "npm:unlink": "npm unlink hc-vue3-ui",
-        "yarn:add:hc-vue3-ui": "yarn add hc-vue3-ui",
-        "npm:install:hc-vue3-ui": "npm install hc-vue3-ui"
+        "build:nopublic": "node ./scripts/build.js && vite build && node ./scripts/restore.js && node ./scripts/public.js && node ./scripts/zip.js"
     },
     "dependencies": {
         "axios": "^1.4.0",

+ 9 - 4
scripts/build.js

@@ -18,10 +18,15 @@ console.log(`获取当前的配置文件...`)
 const indexJsonPath = path.join(currentDirectory, 'src/config/index.json');
 const indexJsonContent = fs.readFileSync(indexJsonPath, 'utf8');
 
-//创建缓存文件
-console.log(`创建配置缓存文件...`)
-const cacheJsonPath = path.join(currentDirectory, 'scripts/cache.json');
-fs.writeFileSync(cacheJsonPath, indexJsonContent, 'utf8');
+// 检测上次打包异常中断的缓存文件是否存在
+console.log(`检测上次打包异常中断的缓存文件是否存在...`)
+const cacheFilePath = path.join(currentDirectory, 'scripts/cache.json');
+if(!fs.existsSync(cacheFilePath)) {
+    //创建缓存文件
+    console.log(`创建配置缓存文件...`)
+    const cacheJsonPath = path.join(currentDirectory, 'scripts/cache.json');
+    fs.writeFileSync(cacheJsonPath, indexJsonContent, 'utf8');
+}
 
 //修改配置文件
 const indexJson = JSON.parse(indexJsonContent);

+ 28 - 0
scripts/public.js

@@ -0,0 +1,28 @@
+const path = require('path');
+const fs = require('fs');
+
+// 获取当前命令行上下文路径
+const currentDirectory = process.cwd();
+
+console.log(`----------------------------`)
+console.log(`项目编译打包完成,准备移除非必要的 /dist/plugins 文件夹...`)
+const dist_plugins = path.join(currentDirectory, '/dist/plugins');
+if(fs.existsSync(dist_plugins)) {
+    delallfilerid(dist_plugins)
+    fs.rmdirSync(dist_plugins)
+    console.log(`移除非必要的 /dist/plugins 文件夹成功...`)
+} else {
+    console.log(`/dist/plugins 文件夹 不存在,无需移除...`)
+}
+
+//删除文件夹下的所有文件
+function delallfilerid(fuckpath) {
+    fs.readdirSync(fuckpath).forEach((file, index, arr) => {
+        if (fs.lstatSync(`${fuckpath}/${file}`).isFile()) {
+            fs.unlinkSync(`${fuckpath}/${file}`)
+        }else if(fs.lstatSync(`${fuckpath}/${file}`).isDirectory()){
+            delallfilerid(`${fuckpath}/${file}`)
+            fs.rmdirSync(`${fuckpath}/${file}`)
+        }
+    })
+}