huang-julien / nuxt-runtime-compiler

A simple module to enable vue runtime bundle on Nuxt 2 and 3
17 stars 2 forks source link

feat: set customElements at runtime #37

Closed huang-julien closed 1 year ago

huang-julien commented 1 year ago

resolves #36

abdonrd commented 1 year ago

Thanks!

Could we allow the same as Vue? Receive a function: https://vuejs.org/api/application.html#app-config-compileroptions-iscustomelement

In addition to MathML Elements, we also usually use Web Components (like @carbon/web-components). Example:

const mathmlTags = [/* ... */];
const isMathmlTag = (tag: string) => mathmlTags.includes(tag)

export default defineNuxtConfig({
  // ...
  vue: {
    compilerOptions: {
      isCustomElement: (tag) => isMathmlTag(tag) || tag.startsWith('bx-'),
    },
  },
});
huang-julien commented 1 year ago

I'm currently investigating to see if we can directly retrieve the vue compiler options and pass it into the plugin template

huang-julien commented 1 year ago

Currently it is not possible to import the app.config.ts file within the module at build time since the file won't go through any transformation and is being imported as it is. If the user use the defineAppConfig, it won't be possible to import it and merge the compiler options with the build compilerOptions in the nuxt config since this is supposed to be auto-imported. If the user import defineAppConfig from nuxt/app the dynamic import will go through a max callstack since there seems to be some circular dependencies. @abdonrd I think this is the only way to have the closest implementation of the RuntimeCompilerOptions. We canno't (yet) pass non stringifyable options such as functions to plugins which are available a runtime. If you use customElement in your .vue components, they still need the compiler options from nuxt.config.ts since this is what will be passed to the @vitejs/plugin-vue at build time.

abdonrd commented 1 year ago

Oh, we didn't know about the app.config.ts.

We only use the nuxt.config.ts:

const mathmlTags = [/* ... */];
const isMathmlTag = (tag: string) => mathmlTags.includes(tag)

export default defineNuxtConfig({
  // ...
  vue: {
    compilerOptions: {
      isCustomElement: (tag) => isMathmlTag(tag) || tag.startsWith('bx-'),
    },
  },
});
huang-julien commented 1 year ago

I think the current state of this PR should be acceptable since:

abdonrd commented 1 year ago

Got it!

And these problems would be solved if https://github.com/nuxt/framework/pull/4762 PR is accepted, right?

huang-julien commented 1 year ago

Got it!

And these problems would be solved if nuxt/framework#4762 PR is accepted, right?

i'm having the same issues with the PR. I keep it as a draft for now (i still need to redo the merge 😂 ).

huang-julien commented 1 year ago

I found a way (not very clean tho) to import the app config within the module and to set the RuntimeCompilerOptions into the builder context :+1: This workaround should'nt be applied to the PR