refactor: refactor

This commit is contained in:
张传龙
2022-08-27 14:09:32 +08:00
parent 230e3a72d9
commit 220a7800f7
36 changed files with 201 additions and 192 deletions

View File

@@ -1,31 +1,34 @@
import { defineConfig, loadEnv } from 'vite'
import path from 'path'
import { wrapperEnv, createProxy } from './build/utils'
import { convertEnv, getSrcPath, getRootPath } from './build/utils'
import { createViteProxy, viteDefine } from './build/config'
import { createVitePlugins } from './build/plugin'
import { OUTPUT_DIR } from './build/constant'
export default defineConfig(({ command, mode }) => {
const root = process.cwd()
const srcPath = getSrcPath()
const rootPath = getRootPath()
const isBuild = command === 'build'
const env = loadEnv(mode, process.cwd())
const viteEnv = wrapperEnv(env)
const { VITE_PORT, VITE_PUBLIC_PATH, VITE_PROXY } = viteEnv
const viteEnv = convertEnv(env)
const { VITE_PORT, VITE_PUBLIC_PATH, VITE_USE_PROXY, VITE_PROXY_TYPE } = viteEnv
return {
root,
base: VITE_PUBLIC_PATH || '/',
resolve: {
alias: {
'@': path.resolve(__dirname, 'src'),
'~': rootPath,
'@': srcPath,
},
},
define: viteDefine,
plugins: createVitePlugins(viteEnv, isBuild),
server: {
host: '0.0.0.0',
port: VITE_PORT,
proxy: createProxy(VITE_PROXY),
open: false,
proxy: createViteProxy(VITE_USE_PROXY, VITE_PROXY_TYPE),
},
build: {
target: 'es2015',