xtraderClient/vite.config.ts
2026-07-09 00:32:39 +08:00

60 lines
1.6 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 { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { nodePolyfills } from 'vite-plugin-node-polyfills'
/** 移除 crossorigin 属性,避免部分手机浏览器加载资源异常 */
function removeCrossorigin() {
return {
name: 'remove-crossorigin',
transformIndexHtml(html: string) {
return html.replace(/\s*crossorigin\s*/g, ' ')
},
}
}
export default defineConfig({
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url)),
},
},
plugins: [
vue(),
nodePolyfills({
protocolImports: true,
}),
removeCrossorigin(),
],
define: {
'process.env': {},
},
css: {
preprocessorOptions: {
scss: {
// 全局注入变量 + 混入(@use 替代已弃用的 @import
additionalData: (source: string, filename: string) => {
if (/[/\\]variables\.scss$/.test(filename) || /[/\\]mixin\.scss$/.test(filename)) {
return source
}
return `@use "@/assets/styles/variables.scss" as *;\n@use "@/assets/styles/mixin.scss" as *;\n${source}`
},
},
},
},
build: {
target: 'es2020',
cssTarget: 'chrome64',
},
server: {
host: true,
proxy: {
'/api': {
target: 'http://localhost:8888', // 测试服务器地址,可根据实际后端地址修改
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, ''), // 如果后端接口本身没有 /api 前缀,需要将其重写掉
},
},
},
})