2021-08-31 11:50:39 +08:00
import { resolve } from "path" ;
2021-09-28 09:24:19 +08:00
import { UserConfigExport , ConfigEnv , loadEnv } from "vite" ;
2021-08-31 11:50:39 +08:00
import vue from "@vitejs/plugin-vue" ;
import vueJsx from "@vitejs/plugin-vue-jsx" ;
2021-09-28 09:24:19 +08:00
import { warpperEnv } from "./build/utils" ;
2021-08-31 11:50:39 +08:00
import { createProxy } from "./build/proxy" ;
import { viteMockServe } from "vite-plugin-mock" ;
import svgLoader from "vite-svg-loader" ;
import styleImport from "vite-plugin-style-import" ;
2021-09-15 23:17:46 +08:00
import ElementPlus from "unplugin-element-plus" ;
2021-03-01 15:26:05 +08:00
2021-03-29 16:38:52 +08:00
const pathResolve = ( dir : string ) : any = > {
2021-08-31 11:50:39 +08:00
return resolve ( __dirname , "." , dir ) ;
} ;
2021-03-01 15:26:05 +08:00
const alias : Record < string , string > = {
2021-04-21 23:20:14 +08:00
"/@" : pathResolve ( "src" ) ,
2021-09-29 09:07:54 +08:00
"@build" : pathResolve ( "build" ) ,
2021-04-29 03:12:44 +08:00
//解决开发环境下的警告 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-07-07 13:33:47 +08:00
"vue-i18n" : "vue-i18n/dist/vue-i18n.cjs.js"
2021-08-31 11:50:39 +08:00
} ;
2021-03-01 15:26:05 +08:00
2021-08-31 11:50:39 +08:00
const root : string = process . cwd ( ) ;
2021-03-01 15:26:05 +08:00
2021-09-28 09:24:19 +08:00
export default ( { command , mode } : ConfigEnv ) : UserConfigExport = > {
const { VITE_PORT , VITE_PUBLIC_PATH , VITE_PROXY } = warpperEnv (
loadEnv ( mode , root )
) ;
2021-08-31 11:50:39 +08:00
const prodMock = true ;
2021-03-29 16:38:52 +08:00
return {
2021-03-01 15:26:05 +08:00
/ * *
2021-03-29 16:38:52 +08:00
* 基 本 公 共 路 径
2021-04-21 23:20:14 +08:00
* /manages/ 可 根 据 项 目 部 署 域 名 的 后 缀 自 行 填 写 ( 全 局 搜 / manages / 替 换 )
2021-03-29 16:38:52 +08:00
* @default '/'
2021-03-01 15:26:05 +08:00
* /
2021-04-21 23:20:14 +08:00
base :
process . env . NODE_ENV === "production" ? "/manages/" : VITE_PUBLIC_PATH ,
2021-03-29 16:38:52 +08:00
root ,
resolve : {
2021-07-07 13:33:47 +08:00
alias
2021-03-29 16:38:52 +08:00
} ,
// 服务端渲染
server : {
// 是否开启 https
https : false ,
/ * *
* 端 口 号
* @default 3000
* /
port : VITE_PORT ,
2021-07-22 11:33:45 +08:00
host : "0.0.0.0" ,
2021-03-29 16:38:52 +08:00
// 本地跨域代理
2021-07-07 13:33:47 +08:00
proxy : createProxy ( VITE_PROXY )
2021-03-29 16:38:52 +08:00
} ,
plugins : [
vue ( ) ,
2021-04-13 17:33:09 +08:00
vueJsx ( ) ,
2021-08-30 20:36:55 +08:00
svgLoader ( ) ,
2021-04-21 23:20:14 +08:00
styleImport ( {
libs : [
// 按需加载vxe-table
{
libraryName : "vxe-table" ,
esModule : true ,
2021-07-07 13:33:47 +08:00
resolveComponent : name = > ` vxe-table/es/ ${ name } ` ,
resolveStyle : name = > ` vxe-table/es/ ${ name } /style.css `
}
]
2021-04-21 23:20:14 +08:00
} ) ,
2021-09-16 14:31:02 +08:00
ElementPlus ( { } ) ,
2021-03-29 16:38:52 +08:00
viteMockServe ( {
2021-04-21 23:20:14 +08:00
mockPath : "mock" ,
localEnabled : command === "serve" ,
prodEnabled : command !== "serve" && prodMock ,
2021-03-29 16:38:52 +08:00
injectCode : `
import { setupProdMockServer } from './mockProdServer' ;
setupProdMockServer ( ) ;
` ,
2021-07-07 13:33:47 +08:00
logger : true
} )
2021-03-29 16:38:52 +08:00
] ,
2021-04-21 23:20:14 +08:00
optimizeDeps : {
include : [
"element-plus/lib/locale/lang/zh-cn" ,
"element-plus/lib/locale/lang/en" ,
2021-05-09 22:37:17 +08:00
"vxe-table/lib/locale/lang/zh-CN" ,
2021-07-07 13:33:47 +08:00
"vxe-table/lib/locale/lang/en-US"
]
2021-04-21 23:20:14 +08:00
} ,
2021-03-29 16:38:52 +08:00
build : {
2021-08-29 10:20:59 +08:00
// @ts-ignore
2021-08-27 01:33:57 +08:00
sourcemap : false ,
2021-03-29 16:38:52 +08:00
brotliSize : false ,
// 消除打包大小超过500kb警告
2021-07-07 13:33:47 +08:00
chunkSizeWarningLimit : 2000
2021-04-09 12:54:03 +08:00
} ,
define : {
2021-07-07 13:33:47 +08:00
__INTLIFY_PROD_DEVTOOLS__ : false
}
2021-08-31 11:50:39 +08:00
} ;
} ;