| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- import path from 'node:path'
- import { isH5 } from '@uni-helper/uni-env'
- import { defineConfig } from 'vite'
- import { loadMapEnv } from './helpers/load-map-env/index.js'
- import postcss from './postcss.config.js'
- import plugins from './vite.config.plugins.js'
- import Components from '@uni-helper/vite-plugin-uni-components' // 引入组件自动导入插件
- import { uViewProResolver } from '@uni-helper/vite-plugin-uni-components/resolvers'
- import UniKuRoot from '@uni-ku/root'
- export default defineConfig(({ mode }) => {
- const env = loadMapEnv(mode)
- const isUseProxy = env.VITE_PROXY_USE === '1'
- const appBase = env.VITE_APP_BASE
- const proxy = {}
- if (isUseProxy && isH5) {
- const proxyPath = env.VITE_PROXY_PATH
- const apiOrigin = env.VITE_API_ORIGIN
- const apiPath = env.VITE_API_PATH
- proxy[proxyPath] = {
- target: apiOrigin,
- changeOrigin: true,
- rewrite: (path) => {
- return path.replace(new RegExp(`^${proxyPath}`), apiPath)
- },
- }
- }
- return {
- base: appBase,
- server: {
- port: 5174,
- cors: true,
- proxy: {
- ...proxy,
- },
- },
- resolve: {
- alias: {
- '@': path.resolve('./src'),
- '@root': path.resolve('./'),
- '$uni-router': path.resolve('./helpers/uni-router'),
- '$unocss-preset-shades': path.resolve('./helpers/unocss-preset-shades'),
- },
- },
- css: {
- /** 解决外部 postcss.config.js 不被解析的问题 */
- postcss,
- },
- build: {
- // minify: false,
- sourcemap: false
- },
- define: {
- 'process.env': env,
- },
- plugins: [
- // 加载原有插件
- ...plugins({ env }),
- UniKuRoot(),
- // 添加组件自动导入插件,并配置 uViewPro 解析器
- Components({
- resolvers: [
- uViewProResolver() // 启用 uViewPro 组件自动解析
- ]
- }),
- ],
- }
- })
|