You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
2.0 KiB
TypeScript

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import path from 'path'
import { defineConfig, loadEnv } from 'vite'
import uni from '@dcloudio/vite-plugin-uni'
import Unocss from 'unocss/vite'
import transformWeClass from 'unplugin-transform-we-class/vite'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite';
import { VantResolver } from 'unplugin-vue-components/resolvers';
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
// const VITE_APP_SERVER_URL: string = loadEnv(mode, process.cwd()).VITE_APP_SERVER_URL;
export default ({ mode }) => {
// console.log('loadEnv(mode, process.cwd()).VITE_APP_SERVER_URL=', loadEnv(mode, process.cwd()).VITE_APP_SERVER_URL)
return defineConfig({
server: {
open: false,
cors: true,
host: '0.0.0.0',
proxy: {
"^/api": { //服务器接口路径地址,根据路径设置
target: loadEnv(mode, process.cwd()).VITE_APP_SERVER_URL, //你的服务器地址
changeOrigin: true, // 允许跨域
secure: false,
ws: true,
rewrite: (path) => path.replace(/^\/api/, ''),
},
},
},
resolve: {
alias: {
'~/': `${path.resolve(__dirname, 'src')}/`,
},
},
plugins: [
uni(),
Components({
resolvers: [VantResolver()],
}),
createSvgIconsPlugin({
//指定图标文件夹,绝对路径(NODE代码)
iconDirs: [path.resolve(process.cwd(), 'src/icons')],
symbolId: 'icon-[name]',
}),
// https://github.com/antfu/unocss
// Unocss(),
// app打包配置
// uniapp打包app时打包2次一次使用 vue 模式打包h5第2次使用 nvue 模式打包app
// 第2次打包 unocss 会抛出warn
// entry module not found, have you add `import 'uno.css'` in your main entry?
// 导致打包终止
process.env.UNI_COMPILER !== 'nvue' ? Unocss() : undefined,
transformWeClass(),
AutoImport({
imports: [
'vue',
'uni-app',
'pinia',
],
dts: true,
vueTemplate: true,
})
]
})
}