plus-ui/vite.config.ts

84 lines
2.6 KiB
TypeScript
Raw Normal View History

import { defineConfig, loadEnv } from 'vite';
2025-06-18 17:05:40 +08:00
import autoprefixer from 'autoprefixer'; // css自动添加兼容性前缀
2025-06-18 17:05:40 +08:00
import createPlugins from './vite/plugins';
2023-04-02 01:01:56 +08:00
import path from 'path';
export default defineConfig(({ mode, command }) => {
2023-04-03 00:05:09 +08:00
const env = loadEnv(mode, process.cwd());
return {
// 部署生产环境和开发环境下的URL。
// 默认情况下vite 会假设你的应用是被部署在一个域名的根路径上
// 例如 https://www.ruoyi.vip/。如果应用被部署在一个子路径上,你就需要用这个选项指定这个子路径。例如,如果你的应用被部署在 https://www.ruoyi.vip/admin/,则设置 baseUrl 为 /admin/。
base: env.VITE_APP_CONTEXT_PATH,
resolve: {
alias: {
2024-01-11 15:26:37 +08:00
'@': path.resolve(__dirname, './src')
2023-04-03 00:05:09 +08:00
},
extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue']
},
// https://cn.vitejs.dev/config/#resolve-extensions
plugins: createPlugins(env, command === 'build'),
server: {
host: '0.0.0.0',
port: Number(env.VITE_APP_PORT),
open: true,
proxy: {
[env.VITE_APP_BASE_API]: {
2025-06-30 16:53:12 +08:00
// target: 'http://192.168.1.38:8080',
2025-06-19 10:55:07 +08:00
// target: 'http://192.168.1.32:8080', //佳豪
2025-07-01 17:46:51 +08:00
// target: 'http://192.168.1.30:8080', //祥哥
target: 'http://111.62.22.190:8080', // 测试环境
2023-04-03 00:05:09 +08:00
changeOrigin: true,
ws: true,
2025-05-30 17:56:05 +08:00
rewrite: (path) => path.replace(new RegExp('^' + env.VITE_APP_BASE_API), ''),
bypass(req, res, options) {
const proxyURL = options.target + options.rewrite(req.url);
2025-06-02 16:36:25 +08:00
// console.log('请求的真实api地址===>', proxyURL);
res.setHeader('x-req-proxyURL', proxyURL); // 设置真实请求地址,便于开发联调
2025-05-30 17:56:05 +08:00
}
2023-04-03 00:05:09 +08:00
}
}
},
css: {
preprocessorOptions: {
scss: {
// additionalData: '@use "@/assets/styles/variables.module.scss as *";'
// javascriptEnabled: true
api: 'modern-compiler'
},
styl: {}
2023-04-03 00:05:09 +08:00
},
postcss: {
plugins: [
// 浏览器兼容性
autoprefixer(),
2023-04-03 00:05:09 +08:00
{
postcssPlugin: 'internal:charset-removal',
AtRule: {
charset: (atRule) => {
atRule.remove();
2023-04-03 00:05:09 +08:00
}
}
}
]
}
},
// 预编译
optimizeDeps: {
include: [
'vue',
'vue-router',
'pinia',
'axios',
'@vueuse/core',
'echarts',
'vue-i18n',
2023-04-06 11:28:38 +08:00
'@vueup/vue-quill',
2024-04-16 17:41:30 +08:00
'image-conversion',
'element-plus/es/components/**/css'
2023-04-03 00:05:09 +08:00
]
}
};
2023-04-02 01:01:56 +08:00
});