-
-
Notifications
You must be signed in to change notification settings - Fork 48
/
vite.config.ts
121 lines (109 loc) · 3.02 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
113
114
115
116
117
118
119
120
121
import { visualizer } from 'rollup-plugin-visualizer'
import AutoImport from 'unplugin-auto-import/vite'
import { defineConfig, loadEnv } from 'vite'
import { checker } from 'vite-plugin-checker'
import mkcert from 'vite-plugin-mkcert'
import wasm from 'vite-plugin-wasm'
import tsconfigPaths from 'vite-tsconfig-paths'
import type { PluginOption } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import PKG from './package.json'
import WindiCSS from 'vite-plugin-windicss'
// dns.setDefaultResultOrder('verbatim')
export default ({ mode }) => {
const env = loadEnv(mode, process.cwd())
const { VITE_APP_PUBLIC_URL } = env
const isDev = mode === 'development'
return defineConfig({
plugins: [
mkcert(),
wasm(),
WindiCSS(),
vue({}),
vueJsx(),
tsconfigPaths(),
visualizer({ open: process.env.CI ? false : true }),
AutoImport({
include: [
/\.[tj]sx?$/, // .ts, .tsx, .js, .jsx
/\.vue\??/, // .vue
],
dts: './src/auto-import.d.ts',
imports: ['vue', 'pinia', '@vueuse/core'],
}),
checker({
enableBuild: true,
}),
htmlPlugin(env),
// nodePolyfills({
// // To exclude specific polyfills, add them to this list.
// exclude: [
// 'fs', // Excludes the polyfill for `fs` and `node:fs`.
// ],
// // Whether to polyfill `node:` protocol imports.
// protocolImports: true,
// }),
],
resolve: {
alias: {
path: 'path-browserify',
os: 'os-browserify',
'node-fetch': 'isomorphic-fetch',
buffer: 'buffer',
},
},
build: {
chunkSizeWarningLimit: 2500,
target: 'esnext',
// sourcemap: true,
rollupOptions: {
output: {
chunkFileNames: `js/[name]-[hash].js`,
entryFileNames: `js/[name]-[hash].js`,
},
},
},
optimizeDeps: {
exclude: [
'@huacnlee/autocorrect',
'@dqbd/tiktoken',
],
},
define: {
__DEV__: isDev,
},
base: !isDev ? VITE_APP_PUBLIC_URL || '' : '',
server: {
https: true,
port: 9528,
},
esbuild: {
jsxFactory: '__h',
jsxInject: 'import {h as __h,Fragment as __Fragment} from "vue"',
jsxFragment: '__Fragment',
},
})
}
const htmlPlugin: (env: any) => PluginOption = (env) => {
return {
name: 'html-transform',
enforce: 'post',
transformIndexHtml(html) {
return html
.replace(
'<!-- MX SPACE ADMIN DASHBOARD VERSION INJECT -->',
`<script>window.version = '${PKG.version}';</script>`,
)
.replace(/@gh-pages/g, `@page_v${PKG.version}`)
.replace(
'<!-- ENV INJECT -->',
`<script id="env_injection">window.injectData = {WEB_URL:'${
env.VITE_APP_WEB_URL || ''
}', GATEWAY: '${env.VITE_APP_GATEWAY || ''}',BASE_API: '${
env.VITE_APP_BASE_API || ''
}'}</script>`,
)
},
}
}