-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathvite.config.ts
37 lines (34 loc) · 1.04 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
import {glob} from 'glob';
import type {UserConfig} from 'vite';
import {defineConfig} from 'vite';
import {peerDependencies, exports as pkgExports} from './package.json';
import {exclude as ignore} from './tsconfig.build.json';
const pathRegExp = /\\/g;
const normalizePath = (str: string) => str.replace(pathRegExp, '/');
// https://vitejs.dev/config/
export default defineConfig(async (): Promise<UserConfig> => {
const entry: Record<string, string> = {};
for (const [, exportInfo] of Object.entries(pkgExports)) {
const pattern = exportInfo.default.replace(/^\.\/dist\//, './src/').replace(/\.js$/, '.ts');
const files = await glob(pattern, {cwd: import.meta.dirname, ignore});
for (const file of files) {
const baseFile = normalizePath(file)
.replace(/\.ts$/, '')
.replace(/^src\//, '');
entry[baseFile] = normalizePath(file);
}
}
return {
build: {
minify: false,
emptyOutDir: true,
lib: {
entry,
formats: ['es', 'cjs'],
},
rollupOptions: {
external: Object.keys(peerDependencies),
},
},
};
});