how to use tailwind with bun
Asked Answered
C

4

6

I'm creating a react app using bun.sh.

But I also use tailwindcss for styling and tailwind has no official solution for bun. How can use these two together?

I know bun is not ready for production but I'm still looking for a solution if its possible.

Cubiform answered 9/7, 2022 at 7:51 Comment(0)
I
14

You can run a javascript file (or a package.json script or a bin file) with using bun run followed by the library name.

In your case, first add the tailwindcss package to your project: bun add -d tailwindcss

Then initialize tailwind css like this bun run tailwindcss init

This should add the tailwind.config.js file to your project.

Insurmountable answered 16/8, 2022 at 2:31 Comment(0)
A
5

To use Tailwind with bun, use the Tailwind CLI and import the processed .css file. Learn more: https://tailwindcss.com/docs/installation

npx tailwindcss -i ./src/input.css -o ./dist/output.css --watch

or

bun tailwindcss -i ./src/input.css -o ./dist/output.css --watch
bun run tailwindcss -i ./src/input.css -o ./dist/output.css --watch

Use that output.css in your main file and done!

Acceleration answered 10/7, 2022 at 5:59 Comment(2)
in cra, it is compiled automatically, is that possible with bun without any effort?Cubiform
@TayfunErbilen with a plugin, yes.Debtor
D
0

use CLI instation methode using npx or npm it

https://tailwindcss.com/docs/installation

Duala answered 4/9, 2022 at 7:15 Comment(0)
M
0

You can probably add this Bun plugin:

import type { BunPlugin } from 'bun';
import postcss from 'postcss';
import tailwindcss from '@tailwindcss/postcss';

const styleFilter = /.\.(css)$/;

export const cssPlugin: BunPlugin = {
  name: 'CSS Loader',
  setup(build) {
    build.onLoad({ filter: styleFilter }, async (args) => {
      const css = await Bun.file(args.path).text();
      const result = await postcss([tailwindcss]).process(css, { from: args.path });

      return {
        contents: result.css,
        loader: 'text',
      };
    });
  },
};

However, it uses postcss.

Marionmarionette answered 29/9 at 13:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.