-
Notifications
You must be signed in to change notification settings - Fork 5.7k
/
vite.config.ts
43 lines (42 loc) · 1.27 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
/**
* Copyright (c) 2013-Now http://jeesite.com All rights reserved.
* No deletion without permission, or be held responsible to law.
* @author ThinkGem
*/
import type { UserConfig, ConfigEnv } from 'vite';
import { defineConfig, loadEnv } from 'vite';
import { readPackageJSON } from 'pkg-types';
import { resolve } from 'node:path';
import {
createBuildOptions,
createCSSOptions,
createDefineOptions,
createEsBuildOptions,
createServerOptions,
createVitePlugins,
wrapperEnv,
} from './build';
export default defineConfig(async ({ command, mode }: ConfigEnv) => {
const root = process.cwd();
const isBuild = command === 'build';
const viteEnv = wrapperEnv(loadEnv(mode, root));
const pkg = await readPackageJSON(root);
const pathResolve = (pathname: string) => resolve(root, '.', pathname);
const config: UserConfig = {
root,
base: viteEnv.VITE_PUBLIC_PATH,
define: createDefineOptions(pkg),
plugins: createVitePlugins(isBuild, viteEnv, pkg),
server: createServerOptions(viteEnv),
esbuild: createEsBuildOptions(mode),
build: createBuildOptions(viteEnv),
css: createCSSOptions(),
resolve: {
alias: {
'/@/': pathResolve('src') + '/',
'/#/': pathResolve('types') + '/',
},
},
};
return config;
});