-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathvite.config.ts
117 lines (109 loc) · 2.73 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
import { resolve } from 'node:path';
import vue from '@vitejs/plugin-vue';
import { defineConfig } from 'vitest/config';
import AutoImport from 'unplugin-auto-import/vite';
import fg from 'fast-glob';
import consola from 'consola';
const entryPoints = [
'src/components/index.ts',
'src/composables/index.ts',
'src/icons/*',
'src/theme/index.ts',
'src/index.ts',
];
const files = fg.sync(entryPoints, { absolute: true });
const entities = files.map((file) => {
const [key] = file.match(/(?<=src\/).*$/) || [''];
const keyWithoutExt = key.replace(/\.[^.]*$/, '');
return [keyWithoutExt, file];
});
const entries = Object.fromEntries(entities);
function manualChunks(identifier: string): string {
const relative = identifier.replace(__dirname, '');
const pathsAfterModule = relative.split('node_modules/');
if (pathsAfterModule.length > 1) {
return 'vendor';
}
else {
const pathWithoutSrc = pathsAfterModule[0].replace('/src/', '');
if (pathWithoutSrc.startsWith('icons')) {
return pathWithoutSrc.replace('.ts', '');
}
else if (pathWithoutSrc.startsWith('utils')) {
return 'utils/index';
}
else if (pathWithoutSrc.startsWith('composables')) {
return 'composables/index';
}
else if (pathWithoutSrc.startsWith('components') || pathWithoutSrc.includes('plugin-vue:export-helper')) {
return 'components/index';
}
else if (pathWithoutSrc.startsWith('types')) {
return 'types/index';
}
else if (pathWithoutSrc.endsWith('.ts')) {
return pathWithoutSrc.replace('.ts', '');
}
else {
consola.debug(pathWithoutSrc);
}
return 'index';
}
}
export default defineConfig({
resolve: {
alias: {
'@': resolve(__dirname, 'src'),
'~': resolve(__dirname),
},
},
plugins: [
vue(),
AutoImport({
imports: ['vue', '@vueuse/core', { '@vueuse/shared': ['get', 'set'] }],
dts: './auto-imports.d.ts',
dirs: [
'src/composables/**/!(theme.ts|icons.ts|breakpoint.ts)',
'src/utils/**',
],
vueTemplate: true,
}),
],
css: {
preprocessorOptions: {
scss: {
api: 'modern',
},
},
},
build: {
outDir: './dist',
minify: true,
lib: {
entry: entries,
fileName: (format, entryName) => `${entryName}.${format}.js`,
formats: ['es'],
cssFileName: 'style',
},
rollupOptions: {
external: [
'vue',
'vue-router',
'tailwindcss/plugin',
'@vueuse/core',
'@vueuse/shared',
'@vueuse/math',
],
output: {
globals: {
vue: 'vue',
},
manualChunks,
},
},
},
test: {
globals: true,
setupFiles: ['tests/setup-files/setup.ts'],
},
});