-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
CLI as a persistent / sidecar process #19092
-
Hello!
I am currently working on a Rust-based static site generator. As such, to add support for Tailwind, I'm spawning the CLI with the arguments I need and stuff. This is good and fine, however the overhead of spawning a Node process is absolutely insane compared to how long my builds are generally taking. It's faster for my SSG to generate thousands of pages than starting a Node process. In most cases Tailwind takes 99% of the build time of projects using my SSG.
To remediate this, I implemented a system where I call Tailwind CLI in the background waiting for stdin and whenever I need it, I send some stuff through, get the stdout, etc.
This works but it's very clumsy for multiple reasons:
- Tailwind closes after receiving something, so it's not possible to process multiple files using the same process
- There's no way to specify the path of the file since I'm using stdin, as such resolving imports is complicated and require spawning a new process in different cwds for every asset in different folders anyway.
What I'd like to see is a way to run the CLI as a permanent process and being able to send it messages through stdin. Could be JSON or some other format, something like:
{"input": "some-file", "minify": false, "map": true}
Then the CLI would output something to stdout with the result (if no output
is specified, then the content would be included in said result, otherwise something like {"status": "done"}
or something. I'd be willing to help implement this if the idea is accepted.
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 1 comment 1 reply
-
Hey! Do you even need any of the file system access in your project? If you only want to pipe in stdin, it might be easier for you to use the core tailwindcss
package directly without any of the "clients". We'd actually love to enable more use cases like this but the caveat here is that the Core API is not considered stable for now – but you're be invited to help us shape it!
A good start here would be to look at the CLI source code: https://github.com/tailwindlabs/tailwindcss/blob/main/packages/%40tailwindcss-cli/src/commands/build/index.ts#L209-L215 the @tailwindcss/node
packages wraps our Core API with things like file system lookup for imports etc, if you don't need that either, you can just use the plain tailwindscss
library too (examples for that are in the unit tests for tailwindcss)
Beta Was this translation helpful? Give feedback.
All reactions
-
It'd be possible (and I thought about it, actually), though it is a bit inconvenient for me to ship a JS library with my project (but doable!)
It's unclear to me what would and would not work if I went this route? I think my users would still expect for everything Tailwind to work, so I'd assume that I'd need for imports and stuff to be resolved, so closer to @tailwindcss/node
I personally do not need for Tailwind to output any files, though. I'm using Tailwind as part of a Rolldown plugin, so just getting the code is fine
Beta Was this translation helpful? Give feedback.