How to use tailwindcss in nodejs

Viewed 34

Is there a way to use tailwindcss as a nodejs api like this

const tailwind = require('tailwindcss')

const css = tailwind(html,css,....)
2 Answers

postcss provides a JS API that can be combined with the Tailwind postcss plugin:

const autoprefixer = require('autoprefixer')
const postcss = require('postcss')
const postcssNested = require('postcss-nested')
const tailwindcss = require('tailwindcss');
const fs = require('fs')

fs.readFile('src/app.css', (err, css) => {
  postcss([autoprefixer, postcssNested, tailwindcss])
    .process(css, { from: 'src/app.css', to: 'dest/app.css' })
    .then(result => {
      fs.writeFile('dest/app.css', result.css, () => true)
      if ( result.map ) {
        fs.writeFile('dest/app.css.map', result.map.toString(), () => true)
      }
    })
})

I don't think there is any. You can try using the CDN if it works for your use case.

<script src="//cdn.tailwindcss.com"></script>
Related