-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
99 lines (93 loc) · 2.67 KB
/
vite.config.ts
File metadata and controls
99 lines (93 loc) · 2.67 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
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
import react from '@vitejs/plugin-react'
import { fileURLToPath, URL } from 'node:url'
import { resolve } from 'path'
import { presetAttributify, presetIcons, presetMini } from 'unocss'
import UnoCSS from 'unocss/vite'
import type { BuildOptions, ConfigEnv, UserConfig } from 'vite'
import { defineConfig, loadEnv } from 'vite'
import dts from 'vite-plugin-dts'
import svgr from 'vite-plugin-svgr'
// import { VitePWA } from 'vite-plugin-pwa'
export default defineConfig(({ command, mode }: ConfigEnv): UserConfig => {
const env = loadEnv(mode, process.cwd(), '')
const { VITE_API_BUILD_VERSION, VITE_API_VERSION, VITE_API_SYSTEM_URL, VITE_API_BUILD_TYPE } = env
console.table({
VITE_API_BUILD_VERSION,
VITE_API_VERSION,
VITE_API_SYSTEM_URL,
VITE_API_BUILD_TYPE,
command,
mode
})
const isBuildLib = command === 'build' && VITE_API_BUILD_TYPE === 'library'
const libBuildSettings: BuildOptions = {
lib: {
entry: resolve(__dirname, 'packages/index.ts'),
name: 'ElementPlusReact',
fileName: 'index',
formats: ['es']
},
outDir: 'dist',
rollupOptions: {
external: ['react', 'react-dom', 'react/jsx-runtime'],
output: {
preserveModules: true, // 保留 packages 結構
preserveModulesRoot: 'packages',
entryFileNames: '[name].js'
}
},
emptyOutDir: true
}
return {
plugins: [
react(),
svgr(),
// VitePWA(),
UnoCSS({
presets: [
presetMini(), // 核心原子化 preset
presetAttributify(), // <div p="4" text="red-500"> 語法
presetIcons() // i-xxx 圖標
]
}),
dts({
insertTypesEntry: true,
copyDtsFiles: true
})
],
base: VITE_API_SYSTEM_URL,
publicDir: isBuildLib ? false : 'public', // lib 不要使用 public 目錄
build: isBuildLib
? libBuildSettings
: {
outDir: 'dist-demo',
emptyOutDir: true
},
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url)),
'@ayay459547/element-plus-react': fileURLToPath(new URL('./packages', import.meta.url)),
$: fileURLToPath(new URL('./public', import.meta.url))
}
},
css: {
preprocessorOptions: {
scss: {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
api: 'modern-compiler',
quietDeps: true
}
}
},
server: {
port: 4000,
host: '0.0.0.0',
open: false,
cors: false,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
historyApiFallback: true
}
}
})