-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.js
48 lines (43 loc) · 1.14 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
import fs from 'fs'
import path from 'path'
import { defineConfig } from 'vite'
// This file will be auto-generated
const index = path.resolve(__dirname, 'src/index.js')
export default defineConfig(async ({ mode }) => {
// Watch only on dev mode, ignoring auto-generated files
const watch = mode === 'dev' && {
exclude: [index]
}
return {
build: {
watch,
sourcemap: true,
lib: {
name: '@tooooools/utils',
entry: { index }
}
},
plugins: [
{
name: 'build-index',
apply: 'build',
buildStart: () => {
console.log('\ngenerating /src/index.js...\n')
const dir = path.resolve(__dirname, 'src/')
fs.writeFileSync(
index,
[
'// Auto-generated by the build-index plugin',
...fs.readdirSync(dir).map(filename =>
/^(?!index)(.*).js/.test(filename) &&
`export { default as ${path.parse(filename).name} } from './${filename}'`
).filter(Boolean),
''
].join('\n'),
'utf8'
)
}
}
]
}
})