module-builder icon indicating copy to clipboard operation
module-builder copied to clipboard

Export components from module

Open YaredFall opened this issue 1 year ago • 1 comments

How can I export components from module?

For example, if I don't want to autoimport specific component or if consumer wants to import component explicitly.

I managed to find a way to export like this:

src/runtime/components/index.ts

export { default as Foo } from './foo.vue'

package.json

  ...
  "exports": {
    ...
    "./components": {
      "types": "./dist/runtime/components/index.d.ts",
      "import": "./dist/runtime/components/index.js"
    }
  },

But when I import Foo from my package, although its seems to work, the component has type any.

You can check details of my setup in this repo

YaredFall avatar Oct 03 '24 03:10 YaredFall

I have also had issues with this. I couldn't export any single functions / components without using the addImport / addComponent helpers.

Jamie4224 avatar Oct 16 '24 12:10 Jamie4224

Is this something that addComponent (or addComposable) could be extended to support? My rough idea is that using one of these helpers would configure the autoimport as well as adding an export. (Maybe the root, or maybe package/components?)

That way module authors can easily support both autoimport and explicit importing applications and there will be common patterns across nuxt modules. Does that make any sense?

cjpearson avatar Apr 03 '25 10:04 cjpearson