Repository navigation
Replies: 4 comments 10 replies
|
Using |
0 replies
|
Yep +1 to @tlgreg, it’s a PostCSS plug-in not really a tool by itself, so you can use it programmatically by using PostCSS programmatically 👍🏻 |
5 replies
|
For anyone looking for code to do this, here's what worked for me: const tailwind = require("tailwindcss");
const postcss = require("postcss");
const html = '<div class="bg-red-300"></div>';
(async () => {
const result = await postcss([
tailwind({
//...config,
content: [{ raw: html, extension: "html" }],
}),
]).process(`@tailwind base;@tailwind components;@tailwind utilities;`, {
from: undefined,
});
console.log(result.css);
})(); |
4 replies
|
v4 broke this cuz the engine is completely new (lightning css). it's not a postcss plugin in the same way anymore. the new engine is built to scan files, it doesn't like raw html strings in the i had to write the html to a temp file and then pass that file's path to the config. kinda annoying but it works. something like this: import tailwindcss from 'tailwindcss'
import postcss from 'postcss'
import fs from 'fs/promises'
import path from 'path'
const html = '<div class="bg-red-300"></div>'
const tmpFilePath = path.join(__dirname, 'temp.html')
async function getCss() {
await fs.writeFile(tmpFilePath, html)
const result = await postcss([
tailwindcss({
content: [tmpFilePath],
}),
]).process(`@import "tailwindcss";`, { from: undefined })
await fs.unlink(tmpFilePath) // clean up
console.log(result.css)
}
getCss() |
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Hi,
Loving the framework, and the fact that you're opting to try Github Discussions!
I was wondering, are there any tailwind cli docs around to consume? I would love to get a grasp on how to invoke tailwind programmatically?
The use case I have is that I want to feed tailwind CSS via a buffer, or whatever which is stored in a database until it's used to generate a static page. Would prefer not to write to disk and invoking tailwind using a spawned process.
All reactions