-
Notifications
You must be signed in to change notification settings - Fork 651
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(plugins): Add unocss plugin (WIP) #1966
Conversation
ec746d2
to
ed55e85
Compare
@marvinhagemeister @mrk could I have your opinions on a few questions please?
|
@adamgreg I was investigating making this change myself, and fwiw, i just went through the unocss steps in your PR docs and am loving how it works thus far! I ran into a couple things during deno deployment:
|
Thanks! Much of the credit to @miguelrk. About the arguments to the plugin: I think you've identified that the docs are out of date! I'll update them (EDIT: done). If the Uno config is in a I haven't tried Deno Deploy yet. Does it work when you run locally? Do you have the github action set up to perform the build step on Deploy? https://fresh.deno.dev/docs/concepts/ahead-of-time-builds#deploying-an-optimized-fresh-project |
@adamgreg ah thanks for the clarification! i was missing the switch to the GH action build step for AOT. I just added the deploy.yml and switched the project back to AOT (and disabled SSR) and it now works on Deno Deploy! |
I ran into a problem with AoT deployment using the UnoCSS PR with the UnoCSS iconify preset. It appears that the UnoCSS integration defaults to CDN load of icon data sets during instance startup, causing a multi-second wait for Deno cold starts (or occasional failure due to network problems). I dug into the iconify code a bit, and found that the Node loader is explicitly disabled on Deno: The UnoCSS docs also mention a dynamic import option using the preset config. I attempted this, and it appeared to work locally, but it did not work on an AoT Deno Deploy instance (no errors, but also no icons). Here's the config I tried:
After making this change the Deno Deploy logs showed the
I'm not sure how to debug this on the deployed instance, but I suspect that an upstream change to Uno might be required to support icons on Deno. |
Hi @kpwebb, that's interesting - the Iconify preset would crash the last time I tried it, because it did not include that When the plugin runs in AOT mode it should build all of the CSS (including icons) at build time. |
@adamgreg oh fascinating! So they are getting included in the uno.css on local build (and only the icons I'm using the app). What should be happening in a AOT build in terms of caching? Is each static paged stored or does it also generate the uno.css and then merge that for each page render? It would be really useful to be able to inspect the Deno isolate bundle and see what's actually getting stored -- is that possible? |
I just dug into the local build in |
hi @kpwebb , I haven't tried UnoCSS icons myself, but what I've read an interesting blog post (https://antfu.me/posts/icons-in-pure-css) which implies they should end up embedded within the CSS file generated by CSS. I would expect the AOT mode of the Fresh plugin to result in the used icon classes (with embedded SVG data) in the I'm afraid I haven't tried Deno Deploy. If the plugin is instantiated with the default settings (like |
@adamgreg thanks for that very thoughtful response! I've asked around on the Deploy channel but haven't found a way to debug this reliably. The AOT build did include the icons in the static.css, but the server still appeared to make an additional request when deployed. I decided after yesterday's 1.6 release to table this, and just use the new Tailwind integration. Iconify appears to work correctly via Tailwind so I suspect the issue is in that Tailwind/Uno Iconify integration point. I'll follow up if I can find anything new, and but will probably wait until the Uno PR is fully merged into a Fresh release before I bug the Deno folks for more info about deployment. |
Co-authored-by: Lino Le Van <[email protected]>
- Define a Config interface for the plugin, which extends UnoCSS UserConfig with a selfURL property - Add a `defineConfig()` function for help with types, and make it easier to adapt existing UnoCSS config modules for use with the plugin - Move the runtime script inline
Use `init()` function of `@unocss/runtime` instead of manually injecting the script tag to avoid fetching it (redundantly) in the client, and instead ship runtime with `plugin-unocss.main.ts`. Co-authored-by: 木杉 <[email protected]>
…er="default"] in fixture_unocss_hydrate
Co-authored-by: 木杉 <[email protected]>
- Import config from uno.config.ts if no config object is explicitly provided - Always use uno.config.ts as the import source for the browser runtime config - This avoids the complexity of selfURL, allowing the plugin to use standard Uno config files
It is the same as found in the unocss package, but that can not currently be safely imported in Deno (due to Node-specific code in the icons preset).
Use tailwind-compat.css instead of tailwind.css as the source. This resolves a specificity problem affecting button backgrounds: unocss/unocss#2127
- Add separate SSR, CSR & AOT config options - Bump UnoCSS version to 0.56.5
- Use middleware to maintain "AOT" behaviour in dev mode - Use new configResolved() plugin hook to resolve UnoCSS config file - Reduce effort during renders in SSR mode
Let's close this PR. When Fresh 2 is released, I think we can revive it as a JSR package. |
Hi! Is this package being worked on right now? I've implemented unocss (badly) in my current codebase, but I'd be interested in contributing to a package to make it work correctly. Please let me know if/how I can help! |
Hi @rmortes , I haven't made a JSR package yet.. I'm still waiting to adapt my codebase once Fresh 2 is eventually released. I'm still using Fresh 1, with the UnoCSS plugin implemented as a single file in my codebase, and I would say it works well. I've attached it to this comment - feel free to use it. I had to zip it, since GitHub wouldn't accept the .ts file itself directly. If you add that to your project, along with a normal |
Hi @adamgreg! Thanks for the code, it's working great so far! Maybe Github wanted you to upload it as a Gist instead of a file? Anyways, I copied it to my codebase and as far as I can tell everything is working as intended. I added a transformer to my unocss config (transformerCompileClass) but it doesn't work. Which I guess makes sense, since there's no code transformation step, I think? Do you know where could be an implementation of the transformation step so that I could try and implement it in Fresh? Thanks! |
I can't think of an efficient way to use transformers, sorry |
I'm the same hahaha. I'll just keep chipping at it then, many thanks for the code again! |
Adds a plugin that can use UnoCSS to generate CSS at different times:
UnoCSS transformers are not currently supported.
Rebases and succeeds #1303