-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.mts
More file actions
51 lines (47 loc) · 1.58 KB
/
Copy pathvite.config.mts
File metadata and controls
51 lines (47 loc) · 1.58 KB
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
import path from 'path';
import { PluginOption, defineConfig, UserConfig, loadEnv } from 'vite';
import cssInjectedByJsPlugin from 'vite-plugin-css-injected-by-js';
import pluginReact from '@vitejs/plugin-react';
import eslintPlugin from 'vite-plugin-eslint2';
import dts from 'vite-plugin-dts';
const isExternal = (id: string) => !id.startsWith('.') && !path.isAbsolute(id);
const getGlobalName = (id: string): string => {
const normalizedId = id.replace(/^@/, '').replace(/[^A-Za-z0-9_$]+/g, '_');
return id.startsWith('@') ? `_${normalizedId}` : normalizedId;
};
export const getBaseConfig = ({ plugins = [] as PluginOption[], lib, additionalConfig = {} as UserConfig }) => {
return defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), '');
return {
plugins: [
pluginReact(),
eslintPlugin({
cache: false,
include: ['./src/components/**/*.ts', './src/components/**/*.tsx'],
exclude: ['/virtual:/', '/node_modules/'],
}),
dts({
include: ['src'],
tsconfigPath: 'tsconfig-build.json',
rollupTypes: true,
} as any),
cssInjectedByJsPlugin(),
...plugins,
],
build: {
lib,
rollupOptions: {
external: isExternal,
output: {
globals: getGlobalName,
},
},
},
define: {
'process.env.NODE_ENV': JSON.stringify(mode === 'production' ? 'production' : 'development'),
CESIUM_BASE_URL: JSON.stringify(env.CESIUM_BASE_URL),
},
...additionalConfig,
};
});
};