forked from mengxiong10/vue-datepicker-next
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
69 lines (64 loc) · 1.54 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
import { defineConfig, UserConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import vueJsx from '@vitejs/plugin-vue-jsx';
import svgLoader from 'vite-svg-loader';
import path from 'path';
// https://vitejs.dev/config/
const baseConfig: UserConfig = {
plugins: [vue(), vueJsx({ mergeProps: false }), svgLoader()],
resolve: {
alias: {
'vue-datepicker-next': path.resolve(__dirname, './lib'),
},
},
};
const externalDependencies = (id: string) => !id.startsWith('.') && !id.startsWith('/');
const esConfig: UserConfig = {
build: {
outDir: '.',
minify: false,
target: 'es2015',
emptyOutDir: false,
lib: {
entry: path.resolve(__dirname, 'lib/index.ts'),
name: 'DatePicker',
formats: ['es'],
fileName: (format) => `index.${format}.js`,
},
rollupOptions: {
external: externalDependencies,
},
},
};
const umdConfig: UserConfig = {
build: {
outDir: '.',
minify: 'esbuild',
target: 'es2015',
emptyOutDir: false,
lib: {
entry: path.resolve(__dirname, 'lib/index.ts'),
name: 'DatePicker',
formats: ['umd'],
fileName: () => `index.js`,
},
rollupOptions: {
external: ['vue'],
output: {
globals: {
vue: 'Vue',
},
},
},
},
};
export default defineConfig(({ command }) => {
if (command === 'serve') {
return baseConfig;
}
const format = process.env.LIB_FORMAT;
if (format === 'es') {
return { ...baseConfig, ...esConfig };
}
return { ...baseConfig, ...umdConfig };
});