Skip to content

Prevent unplugin-vue-components from removing declarations #611

@VividLemon

Description

@VividLemon

Clear and concise description of the problem

The issue that I have is, (which could possibly be considered a bug):
Components are removed often from the dts file. It's not because they are being removed from the app, but unplugin-vue-components removes them from the dts, until they are stumbled on in dev. When building it gets each component and puts them in dts, which is great, however, when running dev, for some reason, these components get removed from the dts file.

This would normally not be an issue, however, the components.d.ts file says: "// We suggest you to commit this file into source control".

So, the big issue is, this file seemingly is always changing, even when it really shouldn't be changing. Leading to me always needing to commit a file that doesn't need to be changed in the first place.

Suggested solution

The above could be considered a "bug", but one form of solution could be an option that does not remove dts entries...

So perhaps
// vite.config.ts

plugins: [
  Components({
    noDtsAutoRemove: true // default false
  })
]

When that new option is turned on, it will not remove entries from the components.d.ts file.

To add more complexity, the option could be modified to only remove/shake off old components during build. But the option name I came up with would be a bit unusual if it did this. So, in this alternative, during build it will remove unused components, but during dev it will only add components.

Alternative

Most likely what I intend to do is to remove the components.d.ts from source control entirely. It doesn't serve a huge amount of use to the team using the project... any issues are fixed when another team member simply runs their dev server.

Alternatively, it would be equally nice if when using a resolver, that it just added all possible component registers to the dts, regardless if they are used or not in the app. This could be preferable, but doesn't solve the root cause of the issue above. I personally would enjoy this second alternative as a standalone feature. This would be similar to the existing "types" option, but without the "names" property for specific type imports, instead it just imports everything... Though, this seems "difficult" to implement, considering the vast options of component libraries, perhaps somehow built-in resolvers could support this, though they would likely need an update

Additional context

It should be noted, I am on Vue 2.7, using the Vite plugin, and am using the VuetifyResolver. My main issue is that -- even though the components are USED IN THE APP, they are being removed in the dts file during dev.

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions