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

Astro compatibility pragma #169

Closed
Enteleform opened this issue Feb 19, 2022 · 4 comments
Closed

Astro compatibility pragma #169

Enteleform opened this issue Feb 19, 2022 · 4 comments

Comments

@Enteleform
Copy link

Enteleform commented Feb 19, 2022

Issue

I've been using unplugin-icons & unplugin-auto-import with Astro, and the combination has worked very well when using a single renderer.

When enabling multiple renderers, Astro requires a pragma comment (/** @jsxImportSource react */) to process JSX/TSX files with the appropriate renderer. Since those comments don't exist in the virtual files generated by unplugin-icons, the dev server crashes immediately with a notification of missing renderer pragmas.

Is there a way to prepend these pragmas to the virtual file contents that are generated?

Additional Info

I've tried injecting them during the transform hook, but it seems that Astro has already consumed the virtual files at this point and the error is still thrown (even when using {enforce:"pre"}). I had a similar issue with modifying .astro files during transform, and @jonathantneal helped me to resolve the issue by recommending that I perform the modifications during load instead.

However, that approach doesn't seem to work in this case, because I can't use fs.readFileSync as I did for the non-virtual .astro files. I searched a bit and it seems like this sort of thing might be handled in Rollup via this.load(id), but it seems that Vite does not have this capability: vitejs/vite#6810

@userquin
Copy link
Member

userquin commented Feb 20, 2022

@Enteleform you can add your plugin before the astro one, just go here and check the plugin astro-fix-order:
https://stackblitz.com/edit/github-d4rp6r-usdxm9?file=astro.config.mjs

You can also install the vite-plugin-inspect to check you're doing the correct changes (you have the dev dep configure on previous repro).

@Enteleform
Copy link
Author

@Enteleform you can add your plugin before the astro one, just go here and check the plugin astro-fix-order

Okay I'll try that out. Thanks for the tip!

@fprl
Copy link

fprl commented May 16, 2023

Hey @Enteleform, did it work for you?

@Enteleform
Copy link
Author

@francoromanol

Yes, I got it to work. It's been a while so I don't remember exactly what it took to get it working, but I ended up not having to use the plugin reordering approach from astro-fix-order, as the transform approach ended up working at some point. Astro has had a ton of updates since I opened the issue, so it might have just been something that got changed on their side. Also, the Vite issue with load seems to have been resolved as well.

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

3 participants