-
Notifications
You must be signed in to change notification settings - Fork 5
/
vite.config.js
76 lines (66 loc) · 1.75 KB
/
vite.config.js
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
import { fileURLToPath } from 'node:url'
import vue from '@vitejs/plugin-vue'
import { glob } from 'glob'
import { resolve } from 'path'
import { defineConfig } from 'vite'
const createEntries = () => {
const entries = new Map()
const excludeFiles = []
for (const file of glob.sync('src/**/*.{js,vue}')) {
const fileName = file.split('/').at(-1)?.split('.')[0]
if (excludeFiles.some((excludeFile) => file.endsWith(excludeFile))) {
continue
}
if (!fileName) {
continue
}
entries.set(`${fileName}`, fileURLToPath(new URL(file, import.meta.url)))
}
entries.set('index', fileURLToPath(new URL('src/index.js', import.meta.url)))
const res = Object.fromEntries(entries)
return res
}
export default defineConfig(({ mode }) => {
const isTest = mode === 'test' || !!process.env.VITEST
return {
plugins: [vue()],
resolve: {
alias: {
'@': resolve(__dirname, '/src'),
...(isTest ? { '@temp': resolve(__dirname, '/tests/unit/__mocks__/temp') } : {}),
},
},
test: {
globals: true,
clearMocks: true,
environment: 'jsdom',
reporters: ['default'],
},
build: {
minify: false,
copyPublicDir: false,
emptyOutDir: true,
lib: {
entry: createEntries(),
name: 'VuepressPluginVueExample',
formats: ['es'],
},
rollupOptions: {
external: [
/^node:/,
'fs/promises',
'vue',
'vuepress/client',
'vuepress/utils',
'vuepress/shared',
/^@temp/,
'@vuepress/plugin-register-components',
],
output: {
assetFileNames: 'assets/[name][extname]',
entryFileNames: '[name].js',
},
},
},
}
})