From 6c71df9109a962f5785bee3e1f0c8f1539dcfa3e Mon Sep 17 00:00:00 2001 From: Hooray Hu <304327508@qq.com> Date: Tue, 17 Sep 2024 22:44:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8=20vite-plugin-archiver=20?= =?UTF-8?q?=E6=8F=92=E4=BB=B6=E4=BB=A3=E6=9B=BF=E6=A1=86=E6=9E=B6=E5=AD=98?= =?UTF-8?q?=E6=A1=A3=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- pnpm-lock.yaml | 92 +++++++++++++++++++++++++++++++++++++++++++++++-- vite/plugins.ts | 38 ++++---------------- 3 files changed, 96 insertions(+), 36 deletions(-) diff --git a/package.json b/package.json index 9f3c658e..b759e402 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,6 @@ "@unocss/eslint-plugin": "^0.62.3", "@vitejs/plugin-vue": "^5.1.3", "@vitejs/plugin-vue-jsx": "^4.0.1", - "archiver": "^7.0.1", "autoprefixer": "^10.4.20", "boxen": "^8.0.1", "eslint": "^9.9.1", @@ -83,6 +82,7 @@ "unplugin-vue-components": "^0.27.4", "vite": "^5.4.2", "vite-plugin-app-loading": "^0.3.0", + "vite-plugin-archiver": "^0.1.1", "vite-plugin-banner": "^0.7.1", "vite-plugin-compression2": "^1.2.0", "vite-plugin-fake-server": "^2.1.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 8fca1670..66d9b66e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -105,9 +105,6 @@ importers: '@vitejs/plugin-vue-jsx': specifier: ^4.0.1 version: 4.0.1(vite@5.4.2(@types/node@22.5.1)(sass@1.77.8))(vue@3.4.38(typescript@5.5.4)) - archiver: - specifier: ^7.0.1 - version: 7.0.1 autoprefixer: specifier: ^10.4.20 version: 10.4.20(postcss@8.4.42) @@ -198,6 +195,9 @@ importers: vite-plugin-app-loading: specifier: ^0.3.0 version: 0.3.0 + vite-plugin-archiver: + specifier: ^0.1.1 + version: 0.1.1 vite-plugin-banner: specifier: ^0.7.1 version: 0.7.1 @@ -1925,6 +1925,10 @@ packages: bundle-import@0.0.1: resolution: {integrity: sha512-L0z0iPX7t7ff5eZsK7oMEH+Ly2lzJczFKPHwrta6X8SF64a20R3wOrAOYK1MzHZVaWWugg9qlSTVfVwqvQJ2dw==} + bundle-name@4.1.0: + resolution: {integrity: sha512-tjwM5exMg6BGRI+kNmTntNsvdZS1X8BFYS6tnJ2hdH0kVxM6/eVZ2xy+FqStSWvYmtfFMDLIxurorHwDKfDz5Q==} + engines: {node: '>=18'} + bundle-require@5.0.0: resolution: {integrity: sha512-GuziW3fSSmopcx4KRymQEJVbZUfqlCqcq7dvs6TYwKRZiegK/2buMxQTPs6MGlNv50wms1699qYO54R8XfRX4w==} engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} @@ -2288,6 +2292,14 @@ packages: deep-is@0.1.4: resolution: {integrity: sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ==} + default-browser-id@5.0.0: + resolution: {integrity: sha512-A6p/pu/6fyBcA1TRz/GqWYPViplrftcW2gZC9q79ngNCKAeR/X3gcEdXQHl4KNXV+3wgIJ1CPkJQ3IHM6lcsyA==} + engines: {node: '>=18'} + + default-browser@5.2.1: + resolution: {integrity: sha512-WY/3TUME0x3KPYdRRxEJJvXRHV4PyPoUsxtZa78lwItwRQRHhd2U9xOscaT/YTf8uCXIAjeJOFBVEh/7FtD8Xg==} + engines: {node: '>=18'} + defaults@1.0.4: resolution: {integrity: sha512-eFuaLoy/Rxalv2kr+lqMlUnrDWV+3j4pljOIJgLIhI058IQfWJ7vXhyEIHu+HtC738klGALYxOKDO0bQP3tg8A==} @@ -2299,6 +2311,10 @@ packages: resolution: {integrity: sha512-rBMvIzlpA8v6E+SJZoo++HAYqsLrkg7MSfIinMPFhmkorw7X+dOXVJQs+QT69zGkzMyfDnIMN2Wid1+NbL3T+A==} engines: {node: '>= 0.4'} + define-lazy-prop@3.0.0: + resolution: {integrity: sha512-N+MeXYoqr3pOgn8xfyRPREN7gHakLYjhsHhWGT3fWAiL4IkAt0iDw14QiiEm2bE30c5XX5q0FtAA3CK5f9/BUg==} + engines: {node: '>=12'} + define-properties@1.2.0: resolution: {integrity: sha512-xvqAVKGfT1+UAvPwKTVw/njhdQ8ZhXK4lI0bCIuCMrp2up9nPnaDftrLtmpTazqd1o+UY4zgzU+avtMbDP+ldA==} engines: {node: '>= 0.4'} @@ -2818,6 +2834,10 @@ packages: resolution: {integrity: sha512-/pqPFG+FdxWQj+/WSuzXSDaNzxgTLr/OrR1QuqfEZzDakpdYE70PwUxL7BPUa8hpjbvY1+qvCl8k+8Tq34xJgg==} engines: {node: '>=18'} + filesize@10.1.6: + resolution: {integrity: sha512-sJslQKU2uM33qH5nqewAwVB2QgR6w1aMNsYUp3aN5rMRyXEwJGmZvaWzeJFNTOXWlHQyBFCWrdj3fV/fsTOX8w==} + engines: {node: '>= 10.4.0'} + fill-range@4.0.0: resolution: {integrity: sha512-VcpLTWqWDiTerugjj8e3+esbg+skS3M9e54UuR3iCeIDMXCLTsAH8hTSzDQU/X6/6t3eYkOKoZSef2PlU6U1XQ==} engines: {node: '>=0.10.0'} @@ -3360,6 +3380,11 @@ packages: resolution: {integrity: sha512-2eis5WqQGV7peooDyLmNEPUrps9+SXX5c9pL3xEB+4e9HnGuDa7mB7kHxHw4CbqS9k1T2hOH3miL8n8WtiYVtg==} engines: {node: '>=0.10.0'} + is-docker@3.0.0: + resolution: {integrity: sha512-eljcgEDlEns/7AXFosB5K/2nCM4P7FQPkGc/DWLy5rmFEWvZayGrik1d9/QIY5nJ4f9YsVvBkA6kJpHn9rISdQ==} + engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} + hasBin: true + is-extendable@0.1.1: resolution: {integrity: sha512-5BMULNob1vgFX6EjQw5izWDxrecWK9AM72rugNr0TFldMOi0fj6Jk+zeKIt0xGj4cEfQIJth4w3OKWOJ4f+AFw==} engines: {node: '>=0.10.0'} @@ -3391,6 +3416,11 @@ packages: is-hexadecimal@1.0.4: resolution: {integrity: sha512-gyPJuv83bHMpocVYoqof5VDiZveEoGoFL8m3BXNb2VW8Xs+rz9kqO8LOQ5DH6EsuvilT1ApazU0pyl+ytbPtlw==} + is-inside-container@1.0.0: + resolution: {integrity: sha512-KIYLCCJghfHZxqjYBE7rEy0OBuTd5xCHS7tHVgvCLkx7StIoaxwNW3hCALgEUjFfeRk+MG/Qxmp/vtETEF3tRA==} + engines: {node: '>=14.16'} + hasBin: true + is-interactive@1.0.0: resolution: {integrity: sha512-2HvIEKRoqS62guEC+qBjpvRubdX910WCMuJTZ+I9yvqKU2/12eSL549HMwtabb4oupdj2sMP50k+XJfB/8JE6w==} engines: {node: '>=8'} @@ -3497,6 +3527,10 @@ packages: resolution: {integrity: sha512-eXK1UInq2bPmjyX6e3VHIzMLobc4J94i4AWn+Hpq3OU5KkrRC96OAcR3PRJ/pGu6m8TRnBHP9dkXQVsT/COVIA==} engines: {node: '>=0.10.0'} + is-wsl@3.1.0: + resolution: {integrity: sha512-UcVfVfaK4Sc4m7X3dUSoHoozQGBEFeDC+zVo06t98xe8CzHSZZBekNXH+tu0NalHolcJ/QAGqS46Hef7QXBIMw==} + engines: {node: '>=16'} + isarray@1.0.0: resolution: {integrity: sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ==} @@ -4021,6 +4055,10 @@ packages: resolution: {integrity: sha512-VXJjc87FScF88uafS3JllDgvAm+c/Slfz06lorj2uAY34rlUu0Nt+v8wreiImcrgAjjIHp1rXpTDlLOGw29WwQ==} engines: {node: '>=18'} + open@10.1.0: + resolution: {integrity: sha512-mnkeQ1qP5Ue2wd+aivTD3NHd/lZ96Lu0jgf0pwktLPtx6cTZiH7tyeGRRHs0zX0rbrahXPnXlUnbeXyaBBuIaw==} + engines: {node: '>=18'} + opener@1.5.2: resolution: {integrity: sha512-ur5UIdyw5Y7yEj9wLzhqXiy6GZ3Mwx0yGI+5sMn2r0N0v3cKJvUmFH5yPP+WXh9e0xfyzyJX95D8l088DNFj7A==} hasBin: true @@ -4490,6 +4528,10 @@ packages: engines: {node: '>=18.0.0', npm: '>=8.0.0'} hasBin: true + run-applescript@7.0.0: + resolution: {integrity: sha512-9by4Ij99JUr/MCFBUkDKLWK3G9HVXmabKz9U5MlIAIuvuzkiOicRYs8XJLxX+xahD+mLiiCYDqF9dKAgtzKP1A==} + engines: {node: '>=18'} + run-async@3.0.0: resolution: {integrity: sha512-540WwVDOMxA6dN6We19EcT9sc3hkXPw5mzRNGM3FkdN/vtE9NFvj5lFAPNwUDmJjXidm3v7TC1cTE7t17Ulm1Q==} engines: {node: '>=0.12.0'} @@ -5260,6 +5302,9 @@ packages: vite-plugin-app-loading@0.3.0: resolution: {integrity: sha512-FJR40HCZ2CePVf9lJa+gDLi7YBB2V4eBeDeQp2fd3TBJr24oCHn4twhvNNYkGuQoROUhTdfZKX49JKVDYmpFYA==} + vite-plugin-archiver@0.1.1: + resolution: {integrity: sha512-d+W6c02OTU+GjlMJ3NXlMaDQazR653l7Ni7HLF6NfI795A4uVlaiDoh6XDaqFnWG+omnD2cK/DMhj/Nh9HYtdA==} + vite-plugin-banner@0.7.1: resolution: {integrity: sha512-Bww2Xd5tOGsZ1yZ9rQiGneryvsL1u86znPrqeQjCsXPsG72pnSdV5lcQA+cy8UNDguMqyTJiCevlNUbLnT85UA==} @@ -7262,6 +7307,10 @@ snapshots: get-tsconfig: 4.7.2 import-from-string: 0.0.4 + bundle-name@4.1.0: + dependencies: + run-applescript: 7.0.0 + bundle-require@5.0.0(esbuild@0.23.1): dependencies: esbuild: 0.23.1 @@ -7622,6 +7671,13 @@ snapshots: deep-is@0.1.4: {} + default-browser-id@5.0.0: {} + + default-browser@5.2.1: + dependencies: + bundle-name: 4.1.0 + default-browser-id: 5.0.0 + defaults@1.0.4: dependencies: clone: 1.0.4 @@ -7638,6 +7694,8 @@ snapshots: es-errors: 1.3.0 gopd: 1.0.1 + define-lazy-prop@3.0.0: {} + define-properties@1.2.0: dependencies: has-property-descriptors: 1.0.0 @@ -8410,6 +8468,8 @@ snapshots: dependencies: flat-cache: 5.0.0 + filesize@10.1.6: {} + fill-range@4.0.0: dependencies: extend-shallow: 2.0.1 @@ -9023,6 +9083,8 @@ snapshots: is-data-descriptor: 1.0.0 kind-of: 6.0.3 + is-docker@3.0.0: {} + is-extendable@0.1.1: {} is-extendable@1.0.1: @@ -9045,6 +9107,10 @@ snapshots: is-hexadecimal@1.0.4: {} + is-inside-container@1.0.0: + dependencies: + is-docker: 3.0.0 + is-interactive@1.0.0: {} is-interactive@2.0.0: {} @@ -9128,6 +9194,10 @@ snapshots: is-windows@1.0.2: {} + is-wsl@3.1.0: + dependencies: + is-inside-container: 1.0.0 + isarray@1.0.0: {} isarray@2.0.5: {} @@ -9664,6 +9734,13 @@ snapshots: dependencies: mimic-function: 5.0.1 + open@10.1.0: + dependencies: + default-browser: 5.2.1 + define-lazy-prop: 3.0.0 + is-inside-container: 1.0.0 + is-wsl: 3.1.0 + opener@1.5.2: {} optionator@0.9.4: @@ -10151,6 +10228,8 @@ snapshots: '@rollup/rollup-win32-x64-msvc': 4.21.2 fsevents: 2.3.3 + run-applescript@7.0.0: {} + run-async@3.0.0: {} run-parallel@1.2.0: @@ -11052,6 +11131,13 @@ snapshots: vite-plugin-app-loading@0.3.0: {} + vite-plugin-archiver@0.1.1: + dependencies: + archiver: 7.0.1 + dayjs: 1.11.13 + filesize: 10.1.6 + open: 10.1.0 + vite-plugin-banner@0.7.1: {} vite-plugin-compression2@1.2.0(rollup@4.21.2): diff --git a/vite/plugins.ts b/vite/plugins.ts index d3bfd3b7..621fdc1c 100644 --- a/vite/plugins.ts +++ b/vite/plugins.ts @@ -1,7 +1,5 @@ import path from 'node:path' import process from 'node:process' -import fs from 'node:fs' -import dayjs from 'dayjs' import type { PluginOption } from 'vite' import vue from '@vitejs/plugin-vue' import vueJsx from '@vitejs/plugin-vue-jsx' @@ -11,17 +9,13 @@ import Unocss from 'unocss/vite' import { createSvgIconsPlugin } from 'vite-plugin-svg-icons' import { vitePluginFakeServer } from 'vite-plugin-fake-server' import { compression } from 'vite-plugin-compression2' -import archiver from 'archiver' +import Archiver from 'vite-plugin-archiver' import AppLoading from 'vite-plugin-app-loading' import TurboConsole from 'unplugin-turbo-console/vite' import banner from 'vite-plugin-banner' import boxen from 'boxen' import picocolors from 'picocolors' -function sleep(ms) { - return new Promise(resolve => setTimeout(resolve, ms)) -} - export default function createVitePlugins(viteEnv, isBuild = false) { const vitePlugins: (PluginOption | PluginOption[])[] = [ vue(), @@ -67,35 +61,15 @@ export default function createVitePlugins(viteEnv, isBuild = false) { }), // https://github.com/nonzzz/vite-plugin-compression - isBuild && viteEnv.VITE_BUILD_COMPRESS.split(',').includes('gzip') && compression(), - isBuild && viteEnv.VITE_BUILD_COMPRESS.split(',').includes('brotli') && compression({ + viteEnv.VITE_BUILD_COMPRESS.split(',').includes('gzip') && compression(), + viteEnv.VITE_BUILD_COMPRESS.split(',').includes('brotli') && compression({ exclude: [/\.(br)$/, /\.(gz)$/], algorithm: 'brotliCompress', }), - (function () { - let outDir: string - return { - name: 'vite-plugin-archiver', - apply: 'build', - configResolved(resolvedConfig) { - outDir = resolvedConfig.build.outDir - }, - async closeBundle() { - if (['zip', 'tar'].includes(viteEnv.VITE_BUILD_ARCHIVE)) { - await sleep(1000) - const archive = archiver(viteEnv.VITE_BUILD_ARCHIVE, { - ...(viteEnv.VITE_BUILD_ARCHIVE === 'zip' && { zlib: { level: 9 } }), - ...(viteEnv.VITE_BUILD_ARCHIVE === 'tar' && { gzip: true, gzipOptions: { level: 9 } }), - }) - const output = fs.createWriteStream(`${outDir}.${dayjs().format('YYYY-MM-DD-HH-mm-ss')}.${viteEnv.VITE_BUILD_ARCHIVE === 'zip' ? 'zip' : 'tar.gz'}`) - archive.pipe(output) - archive.directory(outDir, false) - archive.finalize() - } - }, - } - })(), + viteEnv.VITE_BUILD_ARCHIVE && Archiver({ + archiveType: viteEnv.VITE_BUILD_ARCHIVE, + }), AppLoading('loading.html'),