-
Notifications
You must be signed in to change notification settings - Fork 1
/
vite.config.ts
157 lines (154 loc) · 3.75 KB
/
vite.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import { resolve } from 'node:path'
import { defineConfig } from 'vite'
import { VitePWA } from 'vite-plugin-pwa'
import Vue from '@vitejs/plugin-vue'
import Pages from 'vite-plugin-pages'
import Icons from 'unplugin-icons/vite'
import Windicss from 'vite-plugin-windicss'
import vsharp from 'vite-plugin-vsharp'
import AutoImport from 'unplugin-auto-import/vite'
import IconsResolver from 'unplugin-icons/resolver'
import Components from 'unplugin-vue-components/vite'
import Terser from '@rollup/plugin-terser'
import { visualizer } from 'rollup-plugin-visualizer'
import {
NaiveUiResolver,
VueUseComponentsResolver,
} from 'unplugin-vue-components/resolvers'
import Markdown from 'unplugin-vue-markdown/vite'
import mdLinkAttrPlugin from 'markdown-it-link-attributes'
import PartialEvaluator from './partial-evaluate'
import BuildPosts from './build/buildPosts'
const markdownWrapperClasses = 'md-blog m-auto text-left'
export default defineConfig({
resolve: {
alias: {
'~/': `${resolve(__dirname, 'src')}/`,
},
},
plugins: [
// vue 官方插件,用来解析 sfc
Vue({
include: [/\.vue$/, /\.md$/],
}),
// markdown 编译插件
Markdown({
wrapperClasses: markdownWrapperClasses,
markdownItSetup(md) {
md.use(mdLinkAttrPlugin, {
attrs: {
target: '_blank',
rel: 'noopener',
},
})
},
}),
// 自动构建文件
BuildPosts(),
// 文件路由
Pages({
extensions: ['vue', 'md'],
}),
// windicss 插件
Windicss({
safelist: markdownWrapperClasses,
}),
// https://icones.netlify.app/
Icons({
autoInstall: true,
}),
// 组件自动按需引入
Components({
dts: resolve(__dirname, './src/types/components.d.ts'),
resolvers: [
IconsResolver(),
NaiveUiResolver(),
VueUseComponentsResolver(),
],
}),
// api 自动按需引入
AutoImport({
dts: './src/types/auto-imports.d.ts',
imports: ['vue', 'vue-router', '@vueuse/core'],
dirs: [
'./src/composables',
],
}),
// 部分求值插件
PartialEvaluator({
silent: true,
components: {
Input: {
loading: undefined,
showCount: false,
maxlength: undefined,
pair: false,
type: '\'text\'',
},
Tag: {
disabled: false,
checkable: false,
closable: false,
},
Rate: {
allowHalf: true,
clearable: false,
},
},
}),
// Terser
Terser(),
// PWA
VitePWA({
registerType: 'autoUpdate',
workbox: {
globPatterns: ['**/*.{js,css,ico,svg}'],
// https://github.com/vite-pwa/vite-plugin-pwa/issues/120
navigateFallback: null,
},
includeAssets: ['favicon.ico', 'apple-touch-icon.png'],
manifest: {
name: 'llyのblog',
short_name: 'llyのblog',
description: '我的个人博客,写点想写的',
lang: 'zh-CN',
theme_color: '#ffffff',
icons: [
{
src: 'pwa-192x192.png',
sizes: '192x192',
type: 'image/png',
},
{
src: 'pwa-512x512.png',
sizes: '512x512',
type: 'image/png',
},
],
},
}),
// 压缩图片
vsharp({
excludePublic: [
'public/*',
],
includePublic: [
'public/images/*.png',
'public/images/*.jpg',
],
}),
// 打包体积分析
visualizer(),
],
css: {
transformer: 'lightningcss',
},
build: {
minify: 'terser',
rollupOptions: {
output: {
experimentalMinChunkSize: 10_000,
},
},
},
})