unplugin / unplugin-vue-components

📲 On-demand components auto importing for Vue
https://www.npmjs.com/package/unplugin-vue-components
MIT License
3.76k stars 349 forks source link

How can I use in ts file? #524

Open vacnex opened 1 year ago

vacnex commented 1 year ago

Describe the bug

I'm currently using vue-route, it's content component prop, so I dont know how to use component in this file image Sorry for my bad english

Reproduction

declare config in vite-config => cannot use it in ts file route

System Info

System:
    OS: Windows 10 10.0.22000
    CPU: (12) ia32 Intel(R) Core(TM) i5-10400 CPU @ 2.90GHz
    Memory: 2.78 GB / 15.83 GB
  Binaries:
    Node: 16.17.0 - C:\Program Files (x86)\nodejs\node.EXE
    npm: 8.19.2 - C:\Program Files (x86)\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.22000.120.0), Chromium (106.0.1370.42)
    Internet Explorer: 11.0.22000.120

Used Package Manager

npm

Validations

Cheng-DX commented 1 year ago

That cannot work in ts file. You can try another plugin named unplugin-auto-import.

Cheng-DX commented 1 year ago

That cannot work in ts file. You can try another plugin named unplugin-auto-import.

use this: https://github.com/antfu/unplugin-auto-import. Then add this to your config file:

import AutoImport from 'unplugin-auto-import/vite'

export default defineConfig() {
plugins: [
    AutoImport({
      include: [
        /\.[tj]sx?$/,
      ],
      imports: [
        {
          '[file-name]': [
            ['default', 'ComponetName' ],
          ],
        },
      ],
    }),
}