-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
43 lines (40 loc) · 1.37 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
import { resolve } from 'path'
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import { minifyHtml, injectHtml } from 'vite-plugin-html'
import eslintPlugin from 'vite-plugin-eslint'
const BASE_PATH = '/'
const CLIENT_PUBLIC_ENV_PREFIX = 'PUBLIC_'
const ROOT_DIR_PATH = resolve(__dirname, 'src')
const PUBLIC_ASSETS_DIR_PATH = resolve(__dirname, 'static')
const OUTPUT_DIR_PATH = resolve(__dirname, 'dist')
const ENV_DIR_PATH = __dirname
export default defineConfig(({ mode }) => {
const isProductionMode = mode === 'production'
const appVersion = isProductionMode ? process.env.npm_package_version : `${process.env.npm_package_version}-${mode}`
const esbuildPure = isProductionMode ? ['console.log', 'console.info', 'console.debug', 'console.trace'] : undefined
return {
root: ROOT_DIR_PATH,
publicDir: PUBLIC_ASSETS_DIR_PATH,
envDir: ENV_DIR_PATH,
envPrefix: CLIENT_PUBLIC_ENV_PREFIX,
base: BASE_PATH,
build: {
outDir: OUTPUT_DIR_PATH,
emptyOutDir: true,
manifest: true,
},
esbuild: {
pure: esbuildPure,
},
plugins: [
react(),
eslintPlugin({ cache: true, fix: false, throwOnWarning: true, throwOnError: true }),
minifyHtml(),
injectHtml({ injectData: { APP_VERSION: appVersion } }),
],
resolve: {
alias: [{ find: '~', replacement: ROOT_DIR_PATH }],
},
}
})