fect-org / fect

Minimalist UI components built on Vue-next

Home Page:https://www.fect-org.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Feature]: Is it possible to provide a resolver for unplugin-auto-import

QiYuOr2 opened this issue ยท comments

Feature request ๐Ÿš€

Now I need to write the resolver manually, but I don't know if the code is wrong

function FectUiResolver(): ComponentResolver {
  return {
    type: 'component',
    resolve: (name: string) => {
      if (name.match(/^(Fe[A-Z]|fe-[a-z])/)) {
        return {
          name: name.replace(/^(Fe|fe-)/, ''),
          from: '@fect-ui/vue'
        };
      }
    }
  };
}

Expected:

  • No breaking changes

Examples:

import FectUiResolver from '@fect-ui/vue/resolver'

// config
{
    plugins: [
      AutoImport({
        resolvers: [FectUiResolver()]
      }),
      Components({
        resolvers: [FectUiResolver()]
      }),
    ]
 }
commented

emmm.Are you have the error log ?

commented

I think you want to write a unplugin-vue-components resolver?

I think you want to write a unplugin-vue-components resolver?

Yes, but some component styles are not loaded, such as <fe-input-number>
image

my config

import { createStyleImportPlugin } from 'vite-plugin-style-import';
import AutoImport from 'unplugin-auto-import/vite';
import Components from 'unplugin-vue-components/vite';
import { ComponentResolver } from 'unplugin-vue-components/types';

function FectUiResolver(): ComponentResolver {
  return {
    type: 'component',
    resolve: (name: string) => {
      if (name.match(/^(Fe[A-Z]|fe-[a-z])/)) {
        return {
          name: name.replace(/^(Fe|fe-)/, ''),
          from: '@fect-ui/vue'
        };
      }
    }
  };
}

export default defineNuxtConfig({
  modules: [
    '@nuxt/content'
  ],
  vite: {
    plugins: [
      AutoImport({
        resolvers: [FectUiResolver()]
      }),
      Components({
        resolvers: [FectUiResolver()]
      }),
      createStyleImportPlugin({
        libs: [
          {
            libraryName: '@fect-ui/vue',
            esModule: true,
            resolveStyle: (name) => {
              return `@fect-ui/vue/dist/esm/${name}/style`;
            }
          }
        ]
      })
    ]
  },
  build: {
    transpile: ['@fect-ui/vue']
  }
});
commented

May be you should import import '@fect-ui/themes' in your appp entry? @QiYuOr2

That's right, it was fixed after import @fect-ui/theme. I'm sorry I forgot this

commented

Details see document