-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
188 lines (185 loc) · 4.85 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
import type { Plugin } from 'vite'
import type { VitePluginPWAAPI } from 'vite-plugin-pwa'
import fs from 'node:fs'
import transformerDirective from '@unocss/transformer-directives'
import fg from 'fast-glob'
import { resolve } from 'pathe'
import {
presetAttributify,
presetIcons,
presetTypography,
presetUno,
} from 'unocss'
import Unocss from 'unocss/vite'
import AutoImport from 'unplugin-auto-import/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import Components from 'unplugin-vue-components/vite'
import { defineConfig } from 'vite'
import { VitePWA } from 'vite-plugin-pwa'
import { RssPlugin } from 'vitepress-plugin-rss'
import {
description,
name,
pwaFontsRegex,
pwaFontStylesRegex,
shortName,
} from './.vitepress/meta'
import { optimizePages } from './.vitepress/scripts/assets'
const PWA = VitePWA({
outDir: '.vitepress/dist',
registerType: 'autoUpdate',
// include all static assets under public/
includeAssets: fg.sync('**/*.{png,svg,ico,txt}', {
cwd: resolve(__dirname, 'public'),
}),
manifest: {
id: '/',
name,
short_name: shortName,
description,
theme_color: '#ffffff',
icons: [
{
src: 'pwa-192x192.png',
sizes: '192x192',
type: 'image/png',
},
{
src: 'pwa-512x512.png',
sizes: '512x512',
type: 'image/png',
},
{
src: 'logo.svg',
sizes: '165x165',
type: 'image/svg',
purpose: 'any maskable',
},
],
},
workbox: {
navigateFallbackDenylist: [/^\/new$/],
runtimeCaching: [
{
urlPattern: pwaFontsRegex,
handler: 'CacheFirst',
options: {
cacheName: 'google-fonts-cache',
expiration: {
maxEntries: 10,
maxAgeSeconds: 60 * 60 * 24 * 365, // <== 365 days
},
cacheableResponse: {
statuses: [0, 200],
},
},
},
{
urlPattern: pwaFontStylesRegex,
handler: 'CacheFirst',
options: {
cacheName: 'gstatic-fonts-cache',
expiration: {
maxEntries: 10,
maxAgeSeconds: 60 * 60 * 24 * 365, // <== 365 days
},
cacheableResponse: {
statuses: [0, 200],
},
},
},
],
},
})
export default defineConfig({
plugins: [
AutoImport({
resolvers: [ElementPlusResolver()],
}),
Components({
include: [/\.vue/, /\.md/],
dirs: '.vitepress/components',
dts: '.vitepress/components.d.ts',
resolvers: [ElementPlusResolver({ ssr: false })],
}),
Unocss({
theme: {
colors: {
'primary': 'var(--primary)',
'primary-content': 'var(--primary-content)',
'neutral': 'var(--neutral)',
'neutral-content': 'var(--neutral-content)',
'base-100': 'var(--neutral)',
'base-200': '#241f47',
'info': 'var(--info)',
'success': 'var(--success)',
'warning': 'var(--warning)',
'error': 'var(--error)',
},
},
shortcuts: [
[
'btn',
'px-4 py-1 rounded-lg inline-flex justify-center gap-2 text-white leading-30px children:mya !no-underline cursor-pointer disabled:cursor-default disabled:bg-gray-600 disabled:opacity-50',
],
],
presets: [
presetUno({
dark: 'media',
}),
presetAttributify(),
presetIcons({
scale: 1.2,
}),
presetTypography(),
],
transformers: [transformerDirective()],
}),
IncludesPlugin(),
PWA,
{
name: 'pwa:post',
enforce: 'post',
async buildEnd() {
const pwaPlugin: VitePluginPWAAPI = PWA.find(
i => i.name === 'vite-plugin-pwa',
)?.api
const pwa = pwaPlugin && !pwaPlugin.disabled
await optimizePages(pwa)
if (pwa) {
await pwaPlugin.generateSW()
}
},
},
// https://github.com/ATQQ/sugar-blog/tree/master/packages/vitepress-plugin-rss#options
RssPlugin({
title: 'The Feathers Blog',
baseUrl: 'https://feathers.dev',
copyright: 'Copyright (c) 2012 - present',
// don't automatically add the rss icon because the plugin mistakenly adds two in production.
icon: false,
// only include blog posts in the rss feed
filter(value) {
return value.filepath.includes('blog/posts')
},
}),
],
ssr: { noExternal: ['element-plus'] },
})
function IncludesPlugin(): Plugin {
return {
name: 'include-plugin',
enforce: 'pre',
transform(code, id) {
let changed = false
code = code.replace(/\[@@include\]\((.*?)\)/, (_, url) => {
changed = true
const full = resolve(id, url)
return fs.readFileSync(full, 'utf-8')
})
if (changed) {
return code
}
},
}
}