-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvite.config.ts
56 lines (53 loc) · 1.5 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
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import react from '@vitejs/plugin-react';
import dts from 'vite-plugin-dts';
import { resolve } from 'path';
export default defineConfig(({ mode }) => {
const isVue = mode === 'vue';
const framework = isVue ? 'vue' : 'react';
const global = (
isVue ? { vue: 'Vue' } : { react: 'React', 'react/jsx-runtime': 'JSX' }
) as { [key: string]: string };
return {
plugins: [
isVue ? vue() : react(),
dts({
tsconfigPath: `./tsconfig.${framework}.json`,
outDir: `dist/${framework}`,
include: [`src/${framework}/**/*`, `src/${framework}-entry.ts`],
insertTypesEntry: true,
cleanVueFileName: true,
rollupTypes: true,
entryRoot: 'src/'
})
].filter(Boolean),
build: {
target: 'es2015',
copyPublicDir: false,
outDir: `dist/${framework}`,
lib: {
entry: resolve(__dirname, `src/${framework}-entry.ts`),
name: 'LibraryName',
formats: ['es', 'cjs', 'umd'],
fileName: (format) => {
if (format === 'es') return 'index.js';
else return `index.${format}.js`;
}
},
rollupOptions: {
external: ['vue', 'react', 'react/jsx-runtime'],
output: {
exports: 'named',
globals: global
}
}
},
resolve: {
alias: {
'@vue': resolve(__dirname, 'src/vue'),
'@react': resolve(__dirname, 'src/react')
}
}
};
});