nuxt icon indicating copy to clipboard operation
nuxt copied to clipboard

@nuxt/kit: Add prepend option to addImportsDir

Open fahmifitu opened this issue 3 years ago • 4 comments

Describe the feature

As a module author, I would like my composables defined inside the module to be customizable by the app, in case some customization is needed. it very simple in nuxt to do that by using imports:dirs hook

nuxt.hook('imports:dirs', (_dirs) => {
    _dirs.unshift(MODULE_COMPOSABLE_DIR)
})

But it would be best to add a simple prepend flag to the addImportsDir, just like the plugin kit utilities defined in https://github.com/nuxt/nuxt/blob/main/packages/kit/src/plugin.ts

Additional information

  • [X] Would you be willing to help implement this feature?
  • [ ] Could this feature be implemented as a module?

Final checks

fahmifitu avatar Mar 05 '23 10:03 fahmifitu

What is the reason you want to prepend import directories? We have the priority property that should allow you to configure which directory/import takes priority over another.

danielroe avatar Mar 07 '23 09:03 danielroe

Well, addImportsDir only accepts a string or an array of string. it's not possible to use a priority property.

For my use case, i have a directory in a internal module that houses many composables which i want to be registered to the nuxt app (I use addImportsDir from @nuxt/kit). I also want to be able to override any imports from that directory from the app's ~/composables

I achieved exactly that with the included snippet.

Similiar to the code from addPlugin. where we can pass an append option https://github.com/nuxt/nuxt/blob/main/packages/kit/src/plugin.ts Screenshot 2023-03-13 at 3 18 44 PM

fahmifitu avatar Mar 13 '23 13:03 fahmifitu

Seems like a good idea to me unless @antfu has a different POV...

danielroe avatar Mar 13 '23 16:03 danielroe

It makes sense to me as well. 👍

antfu avatar Mar 13 '23 17:03 antfu