2021-03-01 15:26:05 +08:00
import { resolve } from 'path'
2021-03-29 16:38:52 +08:00
import { UserConfigExport , ConfigEnv } from 'vite'
2021-03-01 15:26:05 +08:00
import vue from '@vitejs/plugin-vue'
2021-04-13 17:33:09 +08:00
import vueJsx from '@vitejs/plugin-vue-jsx'
2021-03-01 15:26:05 +08:00
import { loadEnv } from './build/utils'
import { createProxy } from './build/proxy'
2021-03-29 16:38:52 +08:00
import { viteMockServe } from 'vite-plugin-mock'
2021-03-01 15:26:05 +08:00
2021-03-29 16:38:52 +08:00
const pathResolve = ( dir : string ) : any = > {
2021-03-01 15:26:05 +08:00
return resolve ( __dirname , '.' , dir )
}
const { VITE_PORT , VITE_PUBLIC_PATH , VITE_PROXY , VITE_OPEN } = loadEnv ( )
const alias : Record < string , string > = {
'/@' : pathResolve ( 'src' ) ,
2021-03-04 16:04:06 +08:00
'vue-i18n' : 'vue-i18n/dist/vue-i18n.cjs.js' //解决警告You are running the esm-bundler build of vue-i18n. It is recommended to configure your bundler to explicitly replace feature flag globals with boolean literals to get proper tree-shaking in the final bundle.
2021-03-01 15:26:05 +08:00
}
const root : string = process . cwd ( )
2021-03-29 16:38:52 +08:00
export default ( { command } : ConfigEnv ) : UserConfigExport = > {
let prodMock = true
return {
2021-03-01 15:26:05 +08:00
/ * *
2021-03-29 16:38:52 +08:00
* 基 本 公 共 路 径
* @default '/'
2021-03-01 15:26:05 +08:00
* /
2021-03-29 16:38:52 +08:00
base : process.env.NODE_ENV === "production" ? "/manages/" : VITE_PUBLIC_PATH ,
root ,
resolve : {
alias
} ,
// 服务端渲染
server : {
// 是否开启 https
https : false ,
/ * *
* 端 口 号
* @default 3000
* /
port : VITE_PORT ,
// 本地跨域代理
proxy : createProxy ( VITE_PROXY )
} ,
plugins : [
vue ( ) ,
2021-04-13 17:33:09 +08:00
vueJsx ( ) ,
2021-03-29 16:38:52 +08:00
viteMockServe ( {
mockPath : 'mock' ,
localEnabled : command === 'serve' ,
prodEnabled : command !== 'serve' && prodMock ,
injectCode : `
import { setupProdMockServer } from './mockProdServer' ;
setupProdMockServer ( ) ;
` ,
logger : true ,
} ) ,
] ,
build : {
brotliSize : false ,
// 消除打包大小超过500kb警告
2021-03-30 11:55:31 +08:00
chunkSizeWarningLimit : 2000
2021-04-09 12:54:03 +08:00
} ,
define : {
__INTLIFY_PROD_DEVTOOLS__ : false
2021-03-29 16:38:52 +08:00
}
2021-03-01 15:26:05 +08:00
}
2021-03-29 16:38:52 +08:00
}