vue-h5-template/vite.config.ts
2022-10-30 08:48:26 +08:00

62 lines
1.5 KiB
TypeScript

import { createVitePlugins } from './build/vite/plugins';
import { resolve } from 'path';
import { ConfigEnv, loadEnv, UserConfigExport } from 'vite';
import { wrapperEnv } from './build/utils';
const pathResolve = (dir: string) => {
return resolve(process.cwd(), '.', dir);
};
// https://vitejs.dev/config/
export default function ({ command, mode }: ConfigEnv): UserConfigExport {
const isProduction = command === 'build';
const root = process.cwd();
const env = loadEnv(mode, root);
const viteEnv = wrapperEnv(env);
return {
root,
resolve: {
alias: [
{
find: 'vue-i18n',
replacement: 'vue-i18n/dist/vue-i18n.cjs.js',
},
// /@/xxxx => src/xxxx
{
find: /\/@\//,
replacement: pathResolve('src') + '/',
},
// /#/xxxx => types/xxxx
{
find: /\/#\//,
replacement: pathResolve('types') + '/',
},
],
},
server: {
host: true,
hmr: true,
},
plugins: createVitePlugins(viteEnv, isProduction),
build: {
minify: 'terser',
terserOptions: {
compress: {
//生产环境时移除console
drop_console: true,
drop_debugger: true,
},
},
},
css: {
preprocessorOptions: {
scss: {
// 配置 nutui 全局 scss 变量
additionalData: `@import "@nutui/nutui/dist/styles/variables.scss";@import '/@/styles/mixin.scss';`,
},
},
},
};
}