| | |
| | | // https://vitejs.dev/config/ |
| | | export default defineConfig(({mode, command}) => { |
| | | let env = loadEnv(mode, process.cwd(), '') |
| | | console.log('-------'); |
| | | console.log(env.VITE_BASE_PATH); |
| | | console.log(env.VITE_BASE_PATH.replace(env.VITE_BASE_PATH, '')); |
| | | console.log('-------'); |
| | | // console.log('-------'); |
| | | // console.log(env.VITE_BASE_PATH); |
| | | // console.log(env.VITE_BASE_PATH.replace(env.VITE_BASE_PATH, '')); |
| | | // console.log('-------'); |
| | | return { |
| | | base:env.VITE_BASE_CONTEXT, |
| | | plugins: [ |
| | |
| | | |
| | | // 本地运行配置,及反向代理配置 |
| | | server: { |
| | | host: '192.168.0.3', |
| | | port: '8080', |
| | | cors: true, // 默认启用并允许任何源 |
| | | open: true, // 在服务器启动时自动在浏览器中打开应用程序 |
| | | //反向代理配置,注意rewrite写法,开始没看文档在这里踩了坑 |
| | |
| | | changeOrigin: true, |
| | | ws: false, // 允许websocket代理 |
| | | secure: false, |
| | | rewrite: (path) => path.replace(env.VITE_BASE_PATH, '/'), |
| | | // rewrite: (path) => path.replace(/^\api/, ''), // 将api替换为空 |
| | | }, |
| | | /*'/api' : { |
| | | target: env.VITE_BASE_URL, // 通过代理接口访问实际地址。这里是实际访问的地址。vue会通过代理服务器来代理请求 |
| | | changeOrigin: true, |
| | | ws: false, // 允许websocket代理 |
| | | rewrite: (path) => path.replace(/^\api/, ''), // 将api替换为空 |
| | | }*/ |
| | | rewrite: (path) => path.replace(env.VITE_BASE_PATH, '/') |
| | | } |
| | | } |
| | | } |
| | | } |