tuoheng_virtualAirPlan_web/vite.config.js

131 lines
3.3 KiB
JavaScript

import { fileURLToPath, URL } from 'node:url'
import copy from 'rollup-plugin-copy'
import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import vueDevTools from 'vite-plugin-vue-devtools'
import qiankun from 'vite-plugin-qiankun'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers'
import { lazyImport, VxeResolver } from 'vite-plugin-lazy-import'
const root = process.cwd()
function pathResolve(dir) {
return resolve(root, '.', dir)
}
// https://vite.dev/config/
export default ({ command, mode }) => {
let env = {}
const isBuild = command === 'build'
if (!isBuild) {
env = loadEnv(process.argv[3] === '--mode' ? process.argv[4] : process.argv[3], root)
// env = loadEnv(mode, root)
} else {
env = loadEnv(mode, root)
}
return {
//base: '0.0.0.0', //开发环境和自己单独程序时候打包环境使用
//base: 'http://192.168.50.197:5173/',//微前端打包环境使用,最终打包的时候,微前端需要修改地址,否则访问不了
//base: 'http://127.0.0.1:8080/',
plugins: [
vue(),
copy({
targets: [
{
src: 'node_modules/@liveqing/liveplayer-v3/dist/component/liveplayer-lib.min.js',
dest: 'public/js',
},
],
}),
vueJsx(),
vueDevTools(),
Components({
resolvers: [
AntDesignVueResolver({
importStyle: false, // css in js
}),
],
}),
//vxe table按需加载
lazyImport({
resolvers: [
VxeResolver({
libraryName: 'vxe-table',
}),
VxeResolver({
libraryName: 'vxe-pc-ui',
}),
],
}),
qiankun('qiankunother', {
useDevMode: true,
}),
],
define: {
'process.env': {
env: env,
},
},
resolve: {
extensions: [
'.mjs',
'.js',
'.ts',
'.jsx',
'.tsx',
'.json',
'.less',
'.css',
'.jpeg',
'.jpg',
'.png',
'.svg',
'mkv',
'mp4',
],
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url)),
},
},
css: {
preprocessorOptions: {
scss: {
additionalData: '@use "@/assets/style/variables.scss" as *;',
},
// 配置全局共享变量less
less: {
additionalData: '@import "@/assets/style/main.less";',
},
},
},
server: {
host: '0.0.0.0',
port: 8080,
cors: true,
open: false, //不自动开启
proxy: {
'/airport': {
target: env.VITE_APP_API_BASE_URL,
changeOrigin: true,
logLeve: 'debug', //输出真实的地址
rewrite: (path) => path.replace(/^\/airport/, ''),
//获取真实的转发地址
bypass(req, res, options) {
const proxyURL = options.target + options.rewrite(req.url)
console.log('proxyURL', proxyURL)
req.headers['x-req-proxyURL'] = proxyURL // 设置未生效
res.setHeader('x-req-proxyURL', proxyURL) // 设置响应头可以看到
},
},
},
},
}
}