-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathvite.config.ts
80 lines (78 loc) · 2.33 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
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import AutoImport from 'unplugin-auto-import/vite'
import { electronDev, getReplacer } from './plugins/vite-plugin-electron-dev'
import path from 'path'
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
import esModule from 'vite-plugin-esmodule'
// import nodeStdlibBrowser from 'node-stdlib-browser'
// import commonjsExternals from 'vite-plugin-commonjs-externals'
// import builtinModules from 'builtin-modules'
// const commonjsPackages = ['fs', 'os', 'node:process', 'node:util', 'node:child_process', 'path', ...builtinModules] as const
// https://vitejs.dev/config/
export default defineConfig(({ command, mode, ssrBuild }) => {
return {
base: './',
// vite 插件配置
plugins: [
mode === 'sort' && electronDev(),
getReplacer(),
esModule(['wallpaper']),
// commonjsExternals({ externals: commonjsPackages }),
react(),
// Api自动导入
AutoImport({
dts: true,
// 目标文件
include: [
/\.[tj]sx?$/, // .ts, .tsx, .js, .jsx
],
// 全局引入插件
imports: ['react'],
resolvers: [],
// eslint报错解决方案
eslintrc: {
enabled: true, // Default `false`
filepath: './.eslintrc-auto-import.json', // Default `./.eslintrc-auto-import.json`
globalsPropValue: true, // Default `true`, (true | false | 'readonly' | 'readable' | 'writable' | 'writeable')
},
}),
createSvgIconsPlugin({
// 所有的 svg的文件都存放在该文件夹下
iconDirs: [path.resolve(process.cwd(), 'src/assets/icons')],
symbolId: 'icon-[name]',
}),
],
// 服务配置
server: {
port: 1234,
open: false,
host: '0.0.0.0',
proxy: {
'/api': {
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, ''),
},
},
},
// 别名配置
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
// ...(mode === 'production' ? nodeStdlibBrowser : null),
},
},
optimizeDeps: {
exclude: [],
},
// 打包配置
build: {
outDir: 'dist-web',
rollupOptions: {
plugins: [
// buildPlugin()
],
},
},
}
})