86 lines
2.2 KiB
TypeScript
Executable File
86 lines
2.2 KiB
TypeScript
Executable File
import { createVitePlugins } from './build/vite/plugins';
|
|
import { resolve } from 'path';
|
|
import { ConfigEnv, loadEnv, UserConfig } 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): UserConfig {
|
|
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: '0.0.0.0',
|
|
hmr: true,
|
|
port: 4399,
|
|
proxy: {
|
|
'/api': {
|
|
target: viteEnv.VITE_BASE_API_URL,
|
|
changeOrigin: true,
|
|
rewrite: (path) => path.replace(/^\/api/, ''),
|
|
},
|
|
'/weixin': {
|
|
target: 'https://api.weixin.qq.com/',
|
|
changeOrigin: true,
|
|
rewrite: (path) => path.replace(/^\/weixin/, ''),
|
|
},
|
|
},
|
|
},
|
|
plugins: createVitePlugins(viteEnv, isProduction),
|
|
build: {
|
|
minify: 'terser',
|
|
terserOptions: {
|
|
compress: {
|
|
//生产环境时移除console
|
|
drop_console: true,
|
|
drop_debugger: true,
|
|
},
|
|
},
|
|
rollupOptions: {
|
|
output: {
|
|
// Static resource classification and packaging
|
|
chunkFileNames: 'assets/js/[name]-[hash].js',
|
|
entryFileNames: 'assets/js/[name]-[hash].js',
|
|
assetFileNames: 'assets/[ext]/[name]-[hash].[ext]',
|
|
},
|
|
},
|
|
},
|
|
css: {
|
|
preprocessorOptions: {
|
|
scss: {
|
|
// 配置 nutui 全局 scss 变量
|
|
additionalData: `@import "@nutui/nutui/dist/styles/variables.scss";@import '@/styles/mixin.scss'; @import '@/styles/vant.scss';`,
|
|
},
|
|
},
|
|
},
|
|
optimizeDeps: {
|
|
exclude: ['@nutui/nutui', 'vant', '@varlet/ui'],
|
|
},
|
|
};
|
|
}
|