uni-helper / vite-plugin-uni-pages

为 Vite 下的 uni-app 提供基于文件系统的路由
https://uni-helper.js.org/vite-plugin-uni-pages
MIT License
118 stars 16 forks source link

feat: add configSource option #104

Closed CrazyZhang3 closed 1 year ago

CrazyZhang3 commented 1 year ago

Description 描述

添加configFile用于修改配置文件位置 ### Linked Issues 关联的 Issues #85 ### Additional context 额外上下文
KeJunMao commented 1 year ago

改了下,这样灵活性会不会更好?

import { defineConfig } from 'vite'
import uni from '@dcloudio/vite-plugin-uni'
import type { PagesConfig } from '@uni-helper/vite-plugin-uni-pages'
import uniPages from '@uni-helper/vite-plugin-uni-pages'

declare module 'vite' {
  interface UserConfig {
    uniPages ?: PagesConfig
  }
}

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    UniPages({
      homePage: 'pages/index',
      debug: true,
      subPackages: ['src/pages-sub'],
      configSource: [
        {
          files: 'vite.config',
          async rewrite(config) {
            const resolved = await (typeof config === 'function' ? config() : config)
            return resolved?.UniPages
          },
        },
      ],
    }),
    uni(),
  ],
  uniPages : {
    globalStyle: {
      navigationBarTextStyle: 'black',
      navigationBarTitleText: 'uni-helper - vite.config.ts',
      navigationBarBackgroundColor: '#F8F8F8',
      backgroundColor: '#F8F8F8',
    },
  },
})
CrazyZhang3 commented 1 year ago

确实这样更灵活一点