diff --git a/package.json b/package.json index a98504f17..33ea82726 100755 --- a/package.json +++ b/package.json @@ -86,7 +86,6 @@ "@vitejs/plugin-legacy": "^5.4.2", "@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", @@ -116,6 +115,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 1627cd88a..2ac05e757 100755 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -207,9 +207,6 @@ importers: '@vitejs/plugin-vue-jsx': specifier: ^4.0.1 version: 4.0.1(vite@5.4.2(@types/node@22.5.4)(sass@1.77.8)(terser@5.32.0))(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) @@ -297,6 +294,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 @@ -4108,6 +4108,10 @@ packages: file-source@0.6.1: resolution: {integrity: sha512-1R1KneL7eTXmXfKxC10V/9NeGOdbsAXJ+lQ//fvvcHUgtaZcZDWNJNblxAoVOyV1cj45pOtUrR3vZTBwqcW8XA==} + 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'} @@ -7079,6 +7083,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==} @@ -11781,6 +11788,8 @@ snapshots: dependencies: stream-source: 0.3.5 + filesize@10.1.6: {} + fill-range@4.0.0: dependencies: extend-shallow: 2.0.1 @@ -15216,6 +15225,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.3): diff --git a/vite/plugins.ts b/vite/plugins.ts index a3bcf5037..900d10c30 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' @@ -15,17 +13,13 @@ import { vitePluginFakeServer } from 'vite-plugin-fake-server' import Layouts from 'vite-plugin-vue-meta-layouts' import Pages from 'vite-plugin-pages' 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(), @@ -95,35 +89,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'),