import { defineConfig, loadEnv } from 'vite'; import path from 'path'; import createVitePlugins from './vite/plugins'; import postCssPxToRem from 'postcss-pxtorem'; import autoprefixer from 'autoprefixer'; // https://vitejs.dev/config/ export default defineConfig(({ mode, command }) => { const env = loadEnv(mode, process.cwd()); const { VITE_APP_ENV } = env; return { // 部署生产环境和开发环境下的URL。 // 默认情况下,vite 会假设你的应用是被部署在一个域名的根路径上 // 例如 https://www.ruoyi.vip/。如果应用被部署在一个子路径上,你就需要用这个选项指定这个子路径。例如,如果你的应用被部署在 https://www.ruoyi.vip/admin/,则设置 baseUrl 为 /admin/。 base: VITE_APP_ENV === 'production' ? '/sponge' : '/', // 是否开启eslint保存检测 lintOnSave: false, plugins: createVitePlugins(env, command === 'build'), resolve: { // https://cn.vitejs.dev/config/#resolve-alias alias: { // 设置路径 '~': path.resolve(__dirname, './'), // 设置别名 '@': path.resolve(__dirname, './src'), }, // https://cn.vitejs.dev/config/#resolve-extensions extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue'], }, // vite 相关配置 server: { port: 8081, host: true, hot: true, //自动保存 cors: true, hmr: true, ////vue3 vite配置热更新不用手动刷新 open: true, proxy: { '/api': { target: "http://192.168.16.94:8104", //研发服务器网关 //target: "https://server1.wh-nf.cn:8132/prod-api", //研发服务器网关 //target: 'http://192.168.16.94:8102', //研发服务器网关 changeOrigin: true, rewrite: p => p.replace(/^\/api/, ''), }, '/dev-api': { target: "http://192.168.16.94:8100", //研发服务器网关 //target: "https://server1.wh-nf.cn:8132/prod-api", //研发服务器网关 //target: 'http://192.168.16.94:8102', //研发服务器网关 changeOrigin: true, rewrite: p => p.replace(/^\/dev-api/, ''), }, '/schedule': { target: 'http://192.168.16.94:8100', //研发服务器网关 //target: "https://server1.wh-nf.cn:8132/prod-api", //研发服务器网关 changeOrigin: true, rewrite: p => p.replace(/^\/schedule/, '/schedule'), }, '/system': { target: 'http://192.168.16.94:8100', //研发服务器网关 //target: "http://192.168.16.136:8101", //卢凡 //target: "http://192.168.20.157:8101", //倪文峰 //target: "https://server1.wh-nf.cn:8132/prod-api", //测试环境 changeOrigin: true, rewrite: p => p.replace(/^\/system/, '/system'), }, '/code': { target: 'http://192.168.16.94:8100', //研发服务器网关 //target: "https://server1.wh-nf.cn:8132/prod-api", //测试环境 changeOrigin: true, rewrite: p => p.replace(/^\/code/, '/code'), }, '/auth': { target: 'http://192.168.16.94:8100', //研发服务器网关 //target: "https://server1.wh-nf.cn:8132/prod-api", //测试环境 changeOrigin: true, rewrite: p => p.replace(/^\/auth/, '/auth'), }, '/3d': { target: 'http://192.168.16.133:9993', //GIS的SDK,吴迪本地 changeOrigin: true, rewrite: p => p.replace(/^\/3d/, '/3d'), }, '/gis': { target: 'https://server1.wh-nf.cn:8132', //GIS的SDK--测试环境 // target: "http://192.168.16.133:9993/3d/v0.0.01/", //GIS的SDK--测试环境 changeOrigin: true, rewrite: p => p.replace(/^\/gis/, '/gis'), }, '/amap': { target: 'https://restapi.amap.com', //geocode服务 changeOrigin: true, rewrite: p => p.replace(/^\/amap/, ''), }, '/business': { //target: "http://192.168.16.94:8100", //研发服务器网关 target: 'http://192.168.16.136:8102', //卢凡 changeOrigin: true, rewrite: p => p.replace(/^\/business/, ''), }, '/datafilter-api': { target: 'http://192.168.16.94:8080', //研发服务器网关 changeOrigin: true, rewrite: p => p.replace(/^\/datafilter-api/, '/datafilter-api'), }, '/geoServerUrl': { target: 'http://server1.wh-nf.cn:8023', changeOrigin: true, logLevel: 'debug', rewrite: p => p.replace(/^\/geoServerUrl/, ''), }, '/http': { target: 'http://192.168.16.133:9992', changeOrigin: true, logLevel: 'debug', rewrite: p => p.replace(/^\/http/, ''), }, '/RongYunsAPI': { target: 'https://api-cn.ronghub.com', changeOrigin: true, rewrite: path => path.replace(/^\/RongYunsAPI/, ''), }, '/prod-api/sponge': { target: 'http://192.168.16.63:8104', //张 鸿 志 changeOrigin: true, rewrite: path => path.replace(/^\/prod-api\/sponge/, ''), }, '/prod-api': { target: 'http://192.168.16.94:8100', //熊 凯 // target: "https://server1.wh-nf.cn:8132/prod-api", changeOrigin: true, rewrite: path => path.replace(/^\/prod-api/, ''), } }, }, //fix:error:stdin>:7356:1: warning: "@charset" must be the first rule in the file css: { postcss: { plugins: [ { postcssPlugin: 'internal:charset-removal', AtRule: { charset: atRule => { if (atRule.name === 'charset') { atRule.remove(); } }, }, }, postCssPxToRem({ // 自适应,px>rem转换 rootValue: 192, // 根据设计图尺寸写,设计图是 1920,就写 192 propList: ['*'], // 需要转换的属性,这里选择全部都进行转换 selectorBlackList: ['-nopx'], // 过滤掉-nopx结尾的class,不进行rem转换 }), autoprefixer({ // 自动添加前缀 overrideBrowserslist: [ 'Android 4.1', 'iOS 7.1', 'Chrome > 31', 'ff > 31', 'ie >= 8', //'last 2 versions', // 所有主流浏览器最近2个版本 ], grid: true, }), ], }, }, build: { sourcemap: false, outDir: "spongeDist" } }; });