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

Allow layers/modules to provide their meta #51

Open
stafyniaksacha opened this issue Mar 7, 2023 · 3 comments
Open

Allow layers/modules to provide their meta #51

stafyniaksacha opened this issue Mar 7, 2023 · 3 comments

Comments

@stafyniaksacha
Copy link
Collaborator

To speedup startup with nuxt-component-meta, we could allow modules and layers to provide their precomputed meta.

Those won't change during dev since they are external libraries, so they don't requires HMR.

Copy link
Member

Atinux commented Mar 7, 2023

How does this look like?

@stafyniaksacha
Copy link
Collaborator Author

Dealing with module can be simple, we could generate a file in dist folder when the module is built.
This file would contain the definition for components loaded by the module, and act as a cached result.

But for layers, If I get it, we don't have such build step and don't want to have one, right?

@stafyniaksacha
Copy link
Collaborator Author

stafyniaksacha commented Mar 13, 2023

I'm wondering about using a whitelist for modules / layers instead of blacklist (see #53)

In layers we could do something like:

export default defineNuxtConfig({
  // declare components
  components: [
    {
      prefix: 'MyLayer',
      path: resolve('./components/ui'),
      global: true,
    },
    {
      prefix: 'MyLayer',
      path: resolve('./components/form'),
    },
  ],
  // add components to meta whitelist
  // @ts-ignore - module may not be installed
  componentMeta: {
    include: [(component: any) => {
      return component?.pascalName?.startWith('MyLayer') && component.global
    }]
  },
})

In modules we could do something like:

export default defineNuxtModule<ModuleOptions>({
  meta: {
    name: 'my-module',
    configKey: 'myModule'
  },
  setup (options, nuxt) {
    addComponentsDir({
      prefix: 'MyModule',
      path: resolve('./runtime/components/ui'),
      global: true,
    })
    addComponentsDir({
      prefix: 'MyModule',
      path: resolve('./runtime/components/form'),
    })

    nuxt.options.componentMeta ??= {}
    nuxt.options.componentMeta.include ??= []
    nuxt.options.componentMeta.include.push((component: any) => {
      return component?.pascalName?.startWith('MyModule') && component.global
    })

    // could we imagine populating precomputed meta here? (ex: with a cli)
    // npx nuxt-component-meta generate --path ./src/runtime/components --out ./src/meta.json
  }
})

For better DX, we can also whitelist all global component from top layer ?

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

No branches or pull requests

2 participants