vben-admin-thin-next/vite.config.ts

113 lines
2.5 KiB
TypeScript
Raw Normal View History

2020-12-01 21:02:37 +08:00
import type { UserConfig, Resolver } from 'vite';
2020-09-28 20:19:10 +08:00
import { resolve } from 'path';
import { modifyVars } from './build/config/lessModifyVars';
import { createProxy } from './build/vite/proxy';
import { configManualChunk } from './build/vite/optimizer';
import globbyTransform from './build/vite/plugin/transform/globby';
import dynamicImportTransform from './build/vite/plugin/transform/dynamic-import';
import { loadEnv } from './build/utils';
2020-09-28 20:19:10 +08:00
import { createRollupPlugin, createVitePlugins } from './build/vite/plugin';
const pkg = require('./package.json');
2020-09-28 20:19:10 +08:00
const viteEnv = loadEnv();
2020-12-01 21:02:37 +08:00
const { VITE_PORT, VITE_PUBLIC_PATH, VITE_PROXY, VITE_DROP_CONSOLE, VITE_DYNAMIC_IMPORT } = 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-12-01 21:02:37 +08:00
const alias: Record<string, string> = {
'/@/': pathResolve('src'),
};
const root: string = process.cwd();
const resolvers: Resolver[] = [];
2020-09-28 20:19:10 +08:00
const viteConfig: UserConfig = {
2020-12-01 21:02:37 +08:00
root,
alias,
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-12-01 21:02:37 +08:00
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
* 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-12-01 21:02:37 +08:00
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: {
keep_infinity: true,
2020-10-16 22:03:44 +08:00
drop_console: VITE_DROP_CONSOLE,
},
},
define: {
__VERSION__: pkg.version,
2020-11-23 23:24:13 +08:00
// setting vue-i18-next
// Suppress warning
__VUE_I18N_LEGACY_API__: false,
__VUE_I18N_FULL_INSTALL__: false,
__INTLIFY_PROD_DEVTOOLS__: false,
},
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
transforms: [
globbyTransform({
2020-12-01 21:02:37 +08:00
resolvers: resolvers,
root: root,
alias: alias,
includes: [resolve('src/router'), resolve('src/locales')],
}),
2020-12-01 21:02:37 +08:00
dynamicImportTransform(VITE_DYNAMIC_IMPORT),
],
proxy: createProxy(VITE_PROXY),
plugins: createVitePlugins(viteEnv),
rollupInputOptions: {
plugins: createRollupPlugin(),
},
rollupOutputOptions: {
compact: true,
manualChunks: configManualChunk,
},
2020-12-01 21:02:37 +08:00
};
export default viteConfig;