-
Notifications
You must be signed in to change notification settings - Fork 9
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
feat(unplugin): move parsing steps to unplugin #43
Conversation
putting this back as draft ; virtual modules breaking build ; not ready yet |
I changed the implementation for it to work with both build and HMR; should be ready for review @farnabaz |
tests passes :) ; released 0.3.2 beta tag on NPM to use it on @nuxt-themes/elements |
I think we can remove some fields from generated meta, fields likes WDYT @Tahul ? |
Agree that some could be trimmed to the essentials to reduce the generate code. Another note is that the generated code should never be included in the end-user bundle but only when:
|
We may want to expose this to the end-user bundle as an opt-in option, so we can use the unplugin as standalone (e.g. with only vite & vue) |
I'm fine with reducing output data, will be pushing that change. I think we should at least preserve component name, and maybe the relative path inside the project (that might be useful when used in development, or to create some GitHub links from that data for example). Data can already be queried via API with this version. The only missing part is using the API in production, instead of inlining the chunk via an import. Does it inlining the data via an import differs from loading it via an API query, as that chunk will be loaded anyways? An important note from latest trials with this version;
What happens here is that I have to refresh the vue-component-meta checker on every request, as the file content changes and I don't know the method to refresh the content for a single file. I checked I tried running that in a parallel process, but that seem to break HMR. Do you think you could point us to a fix for this issue @johnsoncodehk? This PR is blocked by this issue, as it makes HMR really slow and all sizes of projects. |
@Tahul We need to have new API in vue-component-meta, maybe I can check it in next week, it would be nice if you could open a feature request. |
@johnsoncodehk ; vuejs/language-tools#1889 You can find the feature request here, please let me know if anything else needed. |
Hey @johnsoncodehk ; I updated this PR, but it seems like the two new APIs Using them before re-querying a component by its path won't change the result of the query. That still blocks this PR, do you need a sandboxed reproduction? |
Yes this will help, I'll also check if there are any issues with the reload logic before I have reproduction. |
I just found the reason when implement vue-component-meta playground, it should be fixed by vuejs/language-tools@76d3ab8, please wait for v1.0.4. And I suggest you use |
Thank you so much @johnsoncodehk ; latest commit correctly handles HMR in development with @atinux ; I stumbled upon an issue with Nitro approach for component meta, as the import seem to be inlined by Nitro ( I see multiple solutions to this, one would obviously be enforcing the usage of In my opinion, using Nitro should be "default" in production environments, but using local (HMR-compatible) data should be default in development. What do you think of making
|
Agree for having:
|
I added a feature, You can push transformers via: These are useful if you want to apply some transforms to components prior to parsing. There is two ways to alter component parsing now:
An example is Via a transformer, we can rewrite |
Last step is to fix the CI and good for me to merge 🚀 |
This PR moves parsing steps inside an Unplugin, instead of the root scope of the Nuxt module.
This allows supporting HMR.
The PR in its current state supports reparsing components on-save, I get the output file (
.nuxt/component-meta.mjs
) to refresh on each changes, with proper updates.It needs fixes on HMR before merging, but I can already see few issues:
createComponentMetaCheckerByJsonConfig
That would be very helpful to support generating metas from transformed components and not their only the content of the file. That can be useful if the project contains any plugin that may alter the content of or <script>.
I could then run that parsing step from inside the
transform
hook of the Unplugin, and updating my context from that result based on transformed component content.cc @johnsoncodehk :)
Will resolve: #42, #33
Will help on: https://github.com/nuxt-themes/elements/issues/93