-
Notifications
You must be signed in to change notification settings - Fork 1
/
vite.config.ts
74 lines (65 loc) · 2.1 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
/// <reference types="vitest" />
/// <reference types="vite-ssg" />
import { resolve } from 'node:path'
import { unheadVueComposablesImports } from '@unhead/vue'
import vue from '@vitejs/plugin-vue'
import unocss from 'unocss/vite'
import autoImport from 'unplugin-auto-import/vite'
import vueComponents from 'unplugin-vue-components/vite'
import type { BuildOptions } from 'vite'
import { defineConfig } from 'vite'
import pages from 'vite-plugin-pages'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
// https://github.com/antfu/unplugin-auto-import
autoImport({
imports: ['vue', 'vue-router', '@vueuse/core', unheadVueComposablesImports],
dts: './src/auto-imports.d.ts',
}),
// https://github.com/unocss/unocss
unocss(),
// https://github.com/hannoeru/vite-plugin-pages
pages(),
// https://github.com/vitejs/vite/tree/main/packages/plugin-vue
vue(),
// https://github.com/antfu/unplugin-vue-components
vueComponents({ dts: './src/components.d.ts' }),
],
resolve: {
alias: {
'~/': `${resolve(__dirname, './src')}/`,
'@/': `${resolve(__dirname, './src')}/`,
},
},
build: createViteBuildOptions(),
ssgOptions: {
dirStyle: 'nested',
},
})
// for gh-pages
function createViteBuildOptions() {
const nameREG = /([_])(?:[.]{3})?([^.]+)\1(.css)?/
const replace = (template: string, value: string) => template.replace(/\[name\]/, value.replace(nameREG, '$2'))
const buildOptions: BuildOptions = {
rollupOptions: {
output: {
// https://rollupjs.org/guide/en/#outputassetfilenames
assetFileNames: (info) => {
const template = 'assets/[name].[hash][extname]'
if (nameREG.test(info.name))
return replace(template, info.name)
return template
},
// https://rollupjs.org/guide/en/#outputchunkfilenames
chunkFileNames: (info) => {
const template = '[name].[hash].js'
if (nameREG.test(info.name))
return replace(template, info.name)
return template
},
},
},
}
return buildOptions
}