nuxt / nuxt/module-builder

Export components from module

Open
#379 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
275
Forks
35
Avg merge
4h 42m
Merged PRs (30d)
6

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with src/runtime/components/index.ts and the package.json exports entry shown in the issue, then reproduce the setup from the linked repository. Trace how the component declaration is generated and exposed through the package entry point. Done means explicitly imported components retain their correct type instead of being typed as any.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
build-system, tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.