Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support add components prefix #612

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

winchesHe
Copy link

@winchesHe winchesHe commented Mar 7, 2023

Description

Add a custom configuration compPrefix

Support adding a prefix to the custom components type name generated by the unplugin

Example:

Components({
  dts: true,
  compPrefix: 'El',
  dirs: ['src/components']
})

-- TestComp: typeof import('src/component/TestComp')['default']

++ ElTestComp: typeof import('src/component/TestComp')['default']

Components({
  dts: true,
  compPrefix: {
    prefix: 'El',
    include: ['test/components'],
  },
  dirs: ['src/components', 'test/components']
})

-- TestComp: typeof import('test/component/TestComp')['default']

++ ElTestComp: typeof import('test/component/TestComp')['default']

OtherTestComp: typeof import('src/component/TestComp')['default']

Linked Issues

#372 how to add prefix with src/components or dirs ?

#385 How to add the prefix of all components in the 'src/components' directory ?

Additional context

I test this in my protect and it perform perfectly.

@winchesHe winchesHe requested a review from antfu as a code owner March 7, 2023 03:29
@lbevo
Copy link

lbevo commented Jun 21, 2023

Another issue about that #438
Would be great to merge that new feature

@TECH7Fox
Copy link

TECH7Fox commented Dec 7, 2023

+1. Need this feature for testing a Nuxt package where components have a prefix.

Did anyone find a workaround for now?

@calumk
Copy link

calumk commented Dec 27, 2023

Would be a really useful feature, for example for PrimeVue, where compontents have no prefix.

@TECH7Fox
Copy link

Hey @winchesHe I tried out your fork, but I can't get it to work. Hope you could help me.

I'm trying to get this to work in my Vitest setup, but it always fails to resolve components.

[Vue warn]: Failed to resolve component: mc-attachments-display-item

That component is located at src/runtime/components/Attachments/DisplayItem.vue.

I tried this:

Components({
  dts: true,
  dirs: ["src/runtime/components"],
  deep: true,
  compPrefix: "Mc",
  directoryAsNamespace: true,
  allowOverrides: false,
})

But with no luck. Any idea on what to try or how to debug?

@winchesHe
Copy link
Author

Hey @winchesHe I tried out your fork, but I can't get it to work. Hope you could help me.

I'm trying to get this to work in my Vitest setup, but it always fails to resolve components.

[Vue warn]: Failed to resolve component: mc-attachments-display-item

That component is located at src/runtime/components/Attachments/DisplayItem.vue.

I tried this:

Components({
  dts: true,
  dirs: ["src/runtime/components"],
  deep: true,
  compPrefix: "Mc",
  directoryAsNamespace: true,
  allowOverrides: false,
})

But with no luck. Any idea on what to try or how to debug?

maybe try the directoryAsNamespace false

@TECH7Fox
Copy link

Hey @winchesHe I tried out your fork, but I can't get it to work. Hope you could help me.
I'm trying to get this to work in my Vitest setup, but it always fails to resolve components.

[Vue warn]: Failed to resolve component: mc-attachments-display-item

That component is located at src/runtime/components/Attachments/DisplayItem.vue.
I tried this:

Components({
  dts: true,
  dirs: ["src/runtime/components"],
  deep: true,
  compPrefix: "Mc",
  directoryAsNamespace: true,
  allowOverrides: false,
})

But with no luck. Any idea on what to try or how to debug?

maybe try the directoryAsNamespace false

Also tried that. Still nothing. Is there a way to check which components it got and how it named them?

@winchesHe
Copy link
Author

Hey @winchesHe I tried out your fork, but I can't get it to work. Hope you could help me.
I'm trying to get this to work in my Vitest setup, but it always fails to resolve components.

[Vue warn]: Failed to resolve component: mc-attachments-display-item

That component is located at src/runtime/components/Attachments/DisplayItem.vue.
I tried this:

Components({
  dts: true,
  dirs: ["src/runtime/components"],
  deep: true,
  compPrefix: "Mc",
  directoryAsNamespace: true,
  allowOverrides: false,
})

But with no luck. Any idea on what to try or how to debug?

maybe try the directoryAsNamespace false

Also tried that. Still nothing. Is there a way to check which components it got and how it named them?

Another way I know is change the file name, It seems to be generated based on the file name.

If you want to check how it named them you can debug the plugin in you editor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants