-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
83 lines (80 loc) · 2.08 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
import path, { resolve } from 'node:path'
import { fileURLToPath } from 'node:url'
import { defineConfig } from 'vite'
import Vue from '@vitejs/plugin-vue'
import dts from 'vite-plugin-dts'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { glob } from 'glob'
const entry = Object.fromEntries(
glob
.sync('src/components/*/index.ts')
.map(file => [
path.relative('src', file.slice(0, file.length - path.extname(file).length)),
fileURLToPath(new URL(file, import.meta.url)),
]),
)
const config = defineConfig({
resolve: {
alias: {
'~/': `${resolve(__dirname, 'src')}/`,
},
},
plugins: [
Vue({ script: { defineModel: true } }),
dts({
include: ['src/**'],
}),
AutoImport({
imports: [
'vue',
'@vueuse/core',
],
dirs: [
'src/composables',
],
dts: 'src/auto-imports.d.ts',
vueTemplate: true,
}),
Components({
dts: 'src/components.d.ts',
}),
{
name: 'post-process-rename-h',
enforce: 'post',
generateBundle(_options, bundle) {
for (const [fileName, file] of Object.entries(bundle)) {
if (file.type === 'chunk' && file.code && fileName.match(/^index-.*\.js$/)) {
file.code = file.code.replace(/},\s*h\s*=\s*{/g, '}, hh = {')
file.code = file.code.replace(/:\s*h\s*,/g, ': hh,')
}
if (file.type === 'chunk' && file.code && fileName === 'index.js') {
file.code = file.code.replace(/, h\s=\s/g, ', hh = ')
file.code = file.code.replace(/\.{3}h/g, '...hh')
}
}
},
},
],
build: {
emptyOutDir: false,
lib: {
entry: {
...entry,
index: fileURLToPath(new URL('src/index.ts', import.meta.url)),
},
formats: ['es'],
},
rollupOptions: {
external: [
'vue',
'@vueuse/head',
],
output: {
assetFileNames: 'assets/[name][extname]',
entryFileNames: '[name].js',
},
},
},
})
export default config