import process from 'node:process' import path from 'node:path' import Uni from '@dcloudio/vite-plugin-uni' import UniHelperComponents from '@uni-helper/vite-plugin-uni-components' import { WotResolver } from '@uni-helper/vite-plugin-uni-components/resolvers' import UniHelperLayouts from '@uni-helper/vite-plugin-uni-layouts' import UniHelperManifest from '@uni-helper/vite-plugin-uni-manifest' import pagesJson from '@uni-ku/pages-json/vite' import Optimization from '@uni-ku/bundle-optimizer' import UniKuRoot from '@uni-ku/root' import AutoImport from 'unplugin-auto-import/vite' import { hookUniPlatform } from '@uni-ku/pages-json/hooks' import { defineConfig } from 'vite' // https://vitejs.dev/config/ export default async () => { const UnoCSS = (await import('unocss/vite')).default return defineConfig({ optimizeDeps: { exclude: process.env.NODE_ENV === 'development' ? ['wot-design-uni', 'uni-echarts'] : [], }, plugins: [ // https://github.com/uni-helper/vite-plugin-uni-manifest UniHelperManifest(), // https://github.com/uni-helper/vite-plugin-uni-pages pagesJson({ dts: path.resolve(process.cwd(), 'src/uni-pages.d.ts'), pagesDir: 'pages', subPackageDirs: [ 'subPack-xsb', 'subPack-common', 'subPack-smqjh', 'subPack-charge', ], /** * 排除的页面,相对于 dir 和 subPackages * @default [] */ exclude: ['**/components/**/*.*'], hooks: [ hookUniPlatform, // 简单调试 hook:在生成时打印上下文,帮助定位问题 (ctx) => { console.log('[pages-json] pages type:', Object.prototype.toString.call(ctx.pages)) console.log('[pages-json] pages count:', Array.isArray(ctx.pages) ? ctx.pages.length : 'not array') console.log('[pages-json] output dts:', path.resolve(process.cwd(), 'src/uni-pages.d.ts')) }, ], }), // https://github.com/uni-helper/vite-plugin-uni-layouts UniHelperLayouts(), // https://github.com/uni-helper/vite-plugin-uni-components UniHelperComponents({ resolvers: [WotResolver()], dts: 'src/components.d.ts', dirs: ['src/components'], directoryAsNamespace: true, }), // https://github.com/uni-ku/root UniKuRoot(), Uni(), // https://github.com/uni-ku/bundle-optimizer Optimization({ logger: true, }), // https://github.com/antfu/unplugin-auto-import AutoImport({ imports: ['vue', '@vueuse/core', 'pinia', 'uni-app', { from: 'uni-mini-router', imports: ['createRouter', 'useRouter', 'useRoute'], }, { from: 'wot-design-uni', imports: ['useToast', 'useMessage', 'useNotify', 'CommonUtil'], }, { from: 'alova/client', imports: ['usePagination', 'useRequest'], }], dts: 'src/auto-imports.d.ts', dirs: ['src/composables', 'src/store', 'src/utils', 'src/api', 'src/subPack-xsb/store-xsb'], vueTemplate: true, }), // https://github.com/antfu/unocss // see unocss.config.ts for config UnoCSS(), ], }) }