Files
fe.ems.vue3/vite.config.ts
2023-10-10 14:49:29 +08:00

78 lines
2.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import vue from '@vitejs/plugin-vue';
import { defineConfig, loadEnv } from 'vite';
import Components from 'unplugin-vue-components/vite';
import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers';
import Compression from 'vite-plugin-compression';
import path from 'path';
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
// 读取环境配置变量,指定前缀
const env = loadEnv(mode, process.cwd(), 'VITE_');
return {
// 访问基础路径
base: env.VITE_HISTORY_BASE_URL,
// 本地开发服务配置
server: {
port: 3131, // 端口
host: true, // 暴露到网络地址
open: false, // 完成后自动跳转浏览器打开
proxy: {
// https://cn.vitejs.dev/config/#server-proxy
[env.VITE_API_BASE_URL]: {
// target: 'http://192.168.0.222:3186/api/rest',
target: 'http://192.168.30.54:3040/api/rest',
changeOrigin: true,
rewrite: p => p.replace(/^\/dev-api/, ''),
},
},
},
resolve: {
// 资源别名
alias: {
'@': path.resolve(__dirname, './src'),
},
extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue'],
},
css: {
preprocessorOptions: {
less: {
// DO NOT REMOVE THIS LINE
javascriptEnabled: true,
modifyVars: {
// hack: `true; @import 'ant-design-vue/dist/antd.variable.less'`,
// '@primary-color': '#eb2f96', // 全局主色
},
},
},
},
optimizeDeps: {
include: ['@ant-design/icons-vue', 'ant-design-vue'],
},
plugins: [
vue(),
// Vue文件中自动导入组件dirs目录和antd库
Components({
dts: 'src/typings/components.d.ts',
deep: true,
dirs: ['src/components'],
extensions: ['vue', 'tsx'],
resolvers: [
AntDesignVueResolver({
importStyle: false,
resolveIcons: true,
cjs: true, // 避免es模块打包缺失
}),
],
}),
// gzip静态压缩文件
Compression({
verbose: false,
algorithm: 'gzip',
ext: '.gz',
disable: false, // 是否禁用
}),
],
};
});