2020-10-27 21:21:14 +08:00
import type { UserConfig } from 'vite' ;
2020-09-28 20:19:10 +08:00
import { resolve } from 'path' ;
2020-10-27 21:21:14 +08:00
import { modifyVars } from './build/config/lessModifyVars' ;
import { createProxy } from './build/vite/proxy' ;
2020-11-19 23:01:27 +08:00
import globbyTransform from './build/vite/plugin/transform/globby' ;
import dynamicImportTransform from './build/vite/plugin/transform/dynamic-import' ;
2020-10-27 21:21:14 +08:00
import { isDevFn , loadEnv } from './build/utils' ;
2020-09-28 20:19:10 +08:00
2020-10-27 21:21:14 +08:00
import { createRollupPlugin , createVitePlugins } from './build/vite/plugin' ;
2020-10-13 01:40:21 +08:00
const pkg = require ( './package.json' ) ;
2020-09-28 20:19:10 +08:00
2020-10-27 21:21:14 +08:00
const viteEnv = loadEnv ( ) ;
2020-10-13 01:40:21 +08:00
const {
VITE_PORT ,
VITE_PUBLIC_PATH ,
VITE_PROXY ,
2020-10-16 22:03:44 +08:00
VITE_DROP_CONSOLE ,
2020-10-13 01:40:21 +08:00
// VITE_USE_CDN,
2020-10-27 21:21:14 +08:00
} = viteEnv ;
2020-09-28 20:19:10 +08:00
function pathResolve ( dir : string ) {
return resolve ( __dirname , '.' , dir ) ;
}
2020-10-10 21:28:43 +08:00
2020-09-28 20:19:10 +08:00
const viteConfig : UserConfig = {
2020-10-27 00:17:11 +08:00
/ * *
2020-11-23 23:24:13 +08:00
* Entry . Use this to specify a js entry file in setting cases where an
2020-10-27 00:17:11 +08:00
* ` index.html ` does not exist ( e . g . serving vite assets from a different host )
* @default 'index.html'
* /
2020-10-27 01:57:39 +08:00
// TODO build error
2020-11-10 22:45:39 +08:00
// entry: 'public/index.html',
2020-10-10 21:28:43 +08:00
/ * *
2020-10-29 23:01:11 +08:00
* port
2020-10-10 21:28:43 +08:00
* @default '3000'
* /
port : VITE_PORT ,
2020-09-28 20:19:10 +08:00
/ * *
* @default 'localhost'
* /
hostname : 'localhost' ,
/ * *
2020-10-29 23:01:11 +08:00
* Run to open the browser automatically
2020-09-28 20:19:10 +08:00
* @default 'false'
* /
open : false ,
/ * *
2020-11-23 23:24:13 +08:00
* Set to ` false ` to disable minification , or specify the minifier to setting .
2020-10-29 23:01:11 +08:00
* Available options are 'terser' or 'esbuild' .
2020-09-28 20:19:10 +08:00
* @default 'terser'
* /
2020-10-21 21:44:57 +08:00
minify : isDevFn ( ) ? 'esbuild' : 'terser' ,
2020-09-28 20:19:10 +08:00
/ * *
2020-10-29 23:01:11 +08:00
* Base public path when served in production .
2020-09-28 20:19:10 +08:00
* @default '/'
* /
2020-10-10 21:28:43 +08:00
base : VITE_PUBLIC_PATH ,
2020-09-28 20:19:10 +08:00
/ * *
2020-10-29 23:01:11 +08:00
* Directory relative from ` root ` where build output will be placed . If the
* directory exists , it will be removed before the build .
2020-09-28 20:19:10 +08:00
* @default 'dist'
* /
outDir : 'dist' ,
/ * *
2020-10-29 23:01:11 +08:00
* Whether to generate sourcemap
* @default false
2020-09-28 20:19:10 +08:00
* /
sourcemap : false ,
/ * *
2020-10-29 23:01:11 +08:00
* Directory relative from ` outDir ` where the built js / css / image assets will
* be placed .
2020-09-28 20:19:10 +08:00
* @default '_assets'
* /
assetsDir : '_assets' ,
/ * *
2020-10-29 23:01:11 +08:00
* Static asset files smaller than this number ( in bytes ) will be inlined as
* base64 strings . Default limit is ` 4096 ` ( 4 kb ) . Set to ` 0 ` to disable .
* @default 4096
2020-09-28 20:19:10 +08:00
* /
assetsInlineLimit : 4096 ,
/ * *
2020-10-29 23:01:11 +08:00
* Transpile target for esbuild .
2020-10-16 22:03:44 +08:00
* @default 'es2020'
2020-09-28 20:19:10 +08:00
* /
2020-11-28 14:27:26 +08:00
esbuildTarget : 'es2019' ,
2020-10-29 23:01:11 +08:00
/ * *
* Whether to log asset info to console
* @default false
* /
2020-10-10 21:28:43 +08:00
silent : false ,
2020-10-29 23:01:11 +08:00
/ * *
* Import alias . The entries can either be exact request - > request mappings
* ( exact , no wildcard syntax ) , or request path - > fs directory mappings .
* When using directory mappings , the key * * must start and end with a slash * * .
* ` ` `
* /
2020-09-28 20:19:10 +08:00
alias : {
'/@/' : pathResolve ( 'src' ) ,
} ,
2020-10-29 23:01:11 +08:00
// terser options
2020-10-24 01:46:29 +08:00
terserOptions : {
2020-10-16 22:03:44 +08:00
compress : {
drop_console : VITE_DROP_CONSOLE ,
} ,
} ,
2020-10-13 01:40:21 +08:00
define : {
__VERSION__ : pkg.version ,
2020-11-23 23:24:13 +08:00
// setting vue-i18-next
2020-11-19 23:01:27 +08:00
// Suppress warning
__VUE_I18N_LEGACY_API__ : false ,
__VUE_I18N_FULL_INSTALL__ : false ,
__INTLIFY_PROD_DEVTOOLS__ : false ,
2020-10-13 01:40:21 +08:00
} ,
2020-09-28 20:19:10 +08:00
cssPreprocessOptions : {
less : {
modifyVars : modifyVars ,
javascriptEnabled : true ,
} ,
} ,
2020-10-29 23:01:11 +08:00
// The package will be recompiled using rollup, and the new package compiled into the esm module specification will be put into node_modules/.vite_opt_cache
2020-09-28 20:19:10 +08:00
optimizeDeps : {
2020-11-23 00:35:15 +08:00
include : [
'echarts/map/js/china' ,
'ant-design-vue/es/locale/zh_CN' ,
'ant-design-vue/es/locale/en_US' ,
'@ant-design/icons-vue' ,
] ,
2020-09-28 20:19:10 +08:00
} ,
2020-10-16 22:03:44 +08:00
2020-10-29 23:01:11 +08:00
// Local cross-domain proxy
2020-10-10 21:28:43 +08:00
proxy : createProxy ( VITE_PROXY ) ,
2020-10-27 21:21:14 +08:00
plugins : createVitePlugins ( viteEnv ) ,
2020-09-28 20:19:10 +08:00
rollupInputOptions : {
2020-10-13 01:40:21 +08:00
// TODO
// external: VITE_USE_CDN ? externals : [],
2020-10-27 21:21:14 +08:00
plugins : createRollupPlugin ( ) ,
2020-09-28 20:19:10 +08:00
} ,
} ;
2020-10-16 22:03:44 +08:00
export default {
. . . viteConfig ,
2020-11-19 23:01:27 +08:00
transforms : [
globbyTransform ( {
resolvers : viteConfig.resolvers ,
root : viteConfig.root ,
alias : viteConfig.alias ,
includes : [ resolve ( 'src/router' ) , resolve ( 'src/locales' ) ] ,
} ) ,
dynamicImportTransform ( viteEnv ) ,
] ,
2020-10-16 22:03:44 +08:00
} as UserConfig ;