-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
112 lines (106 loc) · 2.61 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import path from 'path';
import dts from 'vite-plugin-dts';
import packageJson from './packages/package.json';
import type { BuildOptions } from 'vite';
const baseConfig = defineConfig({
base: './',
plugins: [
vue(),
],
server: {
host: '0.0.0.0',
},
resolve: {
alias: {
'@': path.resolve(__dirname, 'src'),
},
},
});
const baseBuildConfig: BuildOptions = {
lib: {
entry: path.resolve(__dirname, 'packages'),
name: 'ElementPlusLeafer',
},
sourcemap: true,
copyPublicDir: false,
};
const buildFullConfig = defineConfig({
...baseConfig,
plugins: [
dts({
tsconfigPath: 'tsconfig.lib.json',
outDir: 'dist/types',
}),
],
build: {
...baseBuildConfig,
rollupOptions: {
external: ['leafer-ui', '@leafer-in/flow', '@leafer-in/state', '@leafer-in/animate'],
output: [
{
name: 'ElementPlusLeafer',
format: 'umd',
dir: 'dist/dist',
globals: {
'leafer-ui': 'LeaferUI',
'@leafer-in/flow': 'LeaferIN.flow',
'@leafer-in/state': 'LeaferIN.state',
'@leafer-in/animate': 'LeaferIN.animate',
},
entryFileNames: '[name].full.js',
},
{
format: 'esm',
dir: 'dist/dist',
entryFileNames: '[name].full.mjs',
},
],
},
},
});
const buildModulesConfig = defineConfig({
...baseConfig,
build: {
...baseBuildConfig,
rollupOptions: {
external: Object.keys(packageJson.dependencies),
output: [
{
format: 'esm',
dir: 'dist/es',
preserveModules: true,
preserveModulesRoot: 'packages',
entryFileNames: chunkInfo => {
if (chunkInfo.name.endsWith('.svg')) {
const name = chunkInfo.name.split('/').pop();
return `icons/${name}.mjs`;
}
return '[name].mjs';
},
},
{
format: 'cjs',
dir: 'dist/lib',
preserveModules: true,
preserveModulesRoot: 'packages',
entryFileNames: chunkInfo => {
if (chunkInfo.name.endsWith('.svg')) {
const name = chunkInfo.name.split('/').pop();
return `icons/${name}.cjs`;
}
return '[name].cjs';
},
},
],
},
},
});
let config = baseConfig;
if (process.argv.includes('full')) {
config = buildFullConfig;
} else if (process.argv.includes('modules')) {
config = buildModulesConfig;
}
export default config;