64 lines
1.8 KiB
TypeScript
64 lines
1.8 KiB
TypeScript
import { fileURLToPath, URL } from 'node:url'
|
||
import UnoCSS from 'unocss/vite'
|
||
|
||
import { defineConfig } from 'vite'
|
||
import vue from '@vitejs/plugin-vue'
|
||
import AutoImport from 'unplugin-auto-import/vite'
|
||
import Components from 'unplugin-vue-components/vite'
|
||
import { VantResolver } from '@vant/auto-import-resolver'
|
||
// import vueDevTools from 'vite-plugin-vue-devtools'
|
||
|
||
// https://vite.dev/config/
|
||
export default defineConfig({
|
||
plugins: [
|
||
UnoCSS(),
|
||
vue(),
|
||
// vueDevTools(),
|
||
AutoImport({
|
||
resolvers: [VantResolver()],
|
||
imports: ['vue', 'vue-router'],
|
||
dts: 'src/auto-import.d.ts',
|
||
}),
|
||
Components({
|
||
resolvers: [VantResolver()],
|
||
}),
|
||
],
|
||
server: {
|
||
host: '0.0.0.0',
|
||
port: 3000,
|
||
proxy: {
|
||
'/test/api-interface': {
|
||
target: 'https://api.1024api.com', // 后端接口地址
|
||
changeOrigin: true,
|
||
rewrite: (path: string) => {
|
||
return path.replace(/^\/test/, ``)
|
||
},
|
||
},
|
||
},
|
||
},
|
||
resolve: {
|
||
alias: {
|
||
'@': fileURLToPath(new URL('./src', import.meta.url)),
|
||
'#': fileURLToPath(new URL('./types', import.meta.url)),
|
||
},
|
||
},
|
||
css: {
|
||
preprocessorOptions: {
|
||
scss: {
|
||
additionalData: (source, fp) => {
|
||
const id = String(fp).replace(/\\/g, '/'); // 兼容 Windows 路径
|
||
// 避免给自身注入,尤其是 tokens/variables 文件本体
|
||
if (
|
||
id.endsWith('/assets/variables.scss') ||
|
||
id.endsWith('/styles/variables.module.scss')
|
||
) {
|
||
return source;
|
||
}
|
||
// 只注入纯 Sass 变量文件(不要注入 .module.scss)
|
||
return `@use "@/assets/variables.scss" as *; @use "@/styles/variables.module.scss" as *; ${source}`;
|
||
},
|
||
},
|
||
},
|
||
},
|
||
})
|