Skip to content

Commit

Permalink
fix: fix vite plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
wdzyy committed Sep 26, 2024
1 parent a5cab7f commit dc47267
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 47 deletions.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@
"@iconify/json": "^2.2.251",
"@iconify/vue": "^4.1.2",
"@stylistic/stylelint-config": "^2.0.0",
"@types/imagemin-mozjpeg": "^8.0.4",
"@types/imagemin-webp": "^7.0.3",
"@types/lodash-es": "^4.17.12",
"@types/mockjs": "^1.0.10",
"@types/nprogress": "^0.2.3",
Expand Down Expand Up @@ -116,6 +118,7 @@
"vite": "^5.4.6",
"vite-bundle-analyzer": "^0.10.5",
"vite-plugin-app-loading": "^0.3.0",
"vite-plugin-archiver": "^0.1.1",
"vite-plugin-banner": "^0.8.0",
"vite-plugin-cdn2": "^1.1.0",
"vite-plugin-compression2": "^1.3.0",
Expand Down
48 changes: 47 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/components/TreeFilter/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ watch(filterText, (val) => {
})
// 过滤
function filterNode(value: string, data: { [key: string]: any }, node: any) {
function filterNode(value: string, node: any) {
if (!value) {
return true
}
Expand Down
2 changes: 0 additions & 2 deletions src/views/components/china-area-cascader/index.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<script setup lang="ts">
import type { CascaderValue } from 'element-plus'
defineOptions({
name: 'ChinaAreaCascader',
})
Expand Down
11 changes: 7 additions & 4 deletions src/views/components/table/basic/index.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="tsx">
import { CirclePlus, Delete, Download, EditPen, Refresh, Upload, View } from '@element-plus/icons-vue'
import type { ColumnProps, HeaderRenderScope, ZyTableInstance } from '@/components/ZyTable/interface'
import { CirclePlus, Delete, EditPen } from '@element-plus/icons-vue'
// ZyTable 实例
const zyTable = ref<ZyTableInstance>()
Expand Down Expand Up @@ -172,7 +172,8 @@ const tableData = ref([
createTime: '2019-01-04 16:08:43',
status: 0,
avatar: 'https://i.imgtg.com/2023/01/16/QR57a.jpg',
}, {
},
{
id: '425910281113145186',
username: '高明',
gender: 2,
Expand Down Expand Up @@ -331,7 +332,8 @@ const tableData = ref([
createTime: '2019-01-04 16:08:43',
status: 0,
avatar: 'https://i.imgtg.com/2023/01/16/QR57a.jpg',
}, {
},
{
id: '425910281113145186',
username: '高明',
gender: 2,
Expand Down Expand Up @@ -490,7 +492,8 @@ const tableData = ref([
createTime: '2019-01-04 16:08:43',
status: 0,
avatar: 'https://i.imgtg.com/2023/01/16/QR57a.jpg',
}, {
},
{
id: '425910281113145186',
username: '高明',
gender: 2,
Expand Down
4 changes: 2 additions & 2 deletions vite/plugins/app-info.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import type { Plugin } from 'vite'
import boxen from 'boxen'
import picocolors from 'picocolors'
import type { Plugin } from 'vite'

export default function appInfo(): Plugin {
return {
name: 'appInfo',
apply: 'serve',
async buildStart() {
const { bold, green, cyan, bgGreen, underline } = picocolors
// eslint-disable-next-line no-console

console.log(
boxen(
`${bold(green(`${bgGreen('Zy-admin')}`))}\n\n${underline('https://')}\n\n当前使用:${cyan('基础版')}`,
Expand Down
37 changes: 6 additions & 31 deletions vite/plugins/archiver.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,8 @@
import fs from 'node:fs'
import dayjs from 'dayjs'
import archiver from 'archiver'
import type { Plugin } from 'vite'
import type { PluginOption } from 'vite'
import Archiver from 'vite-plugin-archiver'

function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms))
}

export default function createArchiver(env): Plugin {
const { VITE_BUILD_ARCHIVE } = env
let outDir: string
return {
name: 'vite-plugin-archiver',
apply: 'build',
configResolved(resolvedConfig) {
outDir = resolvedConfig.build.outDir
},
async closeBundle() {
if (['zip', 'tar'].includes(VITE_BUILD_ARCHIVE)) {
await sleep(1000)
const archive = archiver(VITE_BUILD_ARCHIVE, {
...(VITE_BUILD_ARCHIVE === 'zip' && { zlib: { level: 9 } }),
...(VITE_BUILD_ARCHIVE === 'tar' && { gzip: true, gzipOptions: { level: 9 } }),
})
const output = fs.createWriteStream(`${outDir}.${dayjs().format('YYYY-MM-DD-HH-mm-ss')}.${VITE_BUILD_ARCHIVE === 'zip' ? 'zip' : 'tar.gz'}`)
archive.pipe(output)
archive.directory(outDir, false)
archive.finalize()
}
},
}
export default function createArchiver(env: Record<string, string>): PluginOption {
return Archiver({
archiveType: env.VITE_BUILD_ARCHIVE,
})
}
2 changes: 1 addition & 1 deletion vite/plugins/components.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import components from 'unplugin-vue-components/vite'

export default function createComponents() {
return components({
Expand Down
4 changes: 2 additions & 2 deletions vite/plugins/compression.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { compression } from 'vite-plugin-compression2'
import type { PluginOption } from 'vite'
import { compression } from 'vite-plugin-compression2'

export default function createCompression(env, isBuild) {
export default function createCompression(env: Record<string, string>, isBuild: boolean) {
const plugin: (PluginOption | PluginOption[])[] = []
if (isBuild) {
const { VITE_BUILD_COMPRESS } = env
Expand Down
2 changes: 1 addition & 1 deletion vite/plugins/devtools.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import VueDevTools from 'vite-plugin-vue-devtools'

export default function createDevtools(env) {
export default function createDevtools(env: Record<string, string>) {
const { VITE_OPEN_DEVTOOLS } = env
return VITE_OPEN_DEVTOOLS === 'true' && VueDevTools()
}
2 changes: 1 addition & 1 deletion vite/plugins/mock.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { vitePluginFakeServer } from 'vite-plugin-fake-server'

export default function createMock(env, isBuild) {
export default function createMock(env: Record<string, string>, isBuild: boolean) {
const { VITE_BUILD_MOCK } = env
return vitePluginFakeServer({
logger: !isBuild,
Expand Down
2 changes: 1 addition & 1 deletion vite/plugins/svg-icon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import path from 'node:path'
import process from 'node:process'
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'

export default function createSvgIcon(isBuild) {
export default function createSvgIcon(isBuild: boolean) {
return createSvgIconsPlugin({
iconDirs: [path.resolve(process.cwd(), 'src/assets/icons/')],
symbolId: 'icon-[dir]-[name]',
Expand Down

0 comments on commit dc47267

Please sign in to comment.