mirror of
https://gitee.com/fantastic-admin/basic.git
synced 2024-12-01 19:48:15 +08:00
refactor: 使用 vite-plugin-archiver 插件代替框架存档功能
This commit is contained in:
parent
6327abb078
commit
4c22d91170
@ -66,7 +66,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",
|
||||
"bumpp": "^9.5.2",
|
||||
@ -98,6 +97,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",
|
||||
|
@ -132,9 +132,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)(terser@5.31.6))(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)
|
||||
@ -228,6 +225,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
|
||||
@ -3431,6 +3431,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'}
|
||||
@ -5798,6 +5802,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==}
|
||||
|
||||
@ -9617,6 +9624,8 @@ snapshots:
|
||||
dependencies:
|
||||
flat-cache: 5.0.0
|
||||
|
||||
filesize@10.1.6: {}
|
||||
|
||||
fill-range@4.0.0:
|
||||
dependencies:
|
||||
extend-shallow: 2.0.1
|
||||
@ -12120,6 +12129,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):
|
||||
|
@ -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'),
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user