create-react-library icon indicating copy to clipboard operation
create-react-library copied to clipboard

CRL + TailwindCSS?

Open ashleyisles opened this issue 5 years ago • 10 comments

Hi!

I'm trying to use Create React Library with TailwindCSS and was wondering if there's a way to include the CSS in the bundle without having to add import '<package_name>/dist/index.css' into my target repo?

My scripts look like this:

"scripts": {
    "build:style": "postcss src/styles/tailwind.css -o src/index.css",
    "prebuild": "npm run build:style",
    "prestart": "npm run build:style",
    "build": "microbundle-crl --no-compress --css-modules false --format modern,cjs",
    "start": "microbundle-crl watch --no-compress --css-modules false --format modern,cjs",
    ...
  },

ashleyisles avatar Oct 22 '20 14:10 ashleyisles

Hello @ashleyisles I used tailwind with Create React Library. It was easy to use since microbundle uses rollup (Which uses a postcss plugin internally).

"scripts": {
    "build": "NODE_ENV=production microbundle-crl --no-compress --css-modules false --format modern,cjs",
    "start": "microbundle-crl watch --css-modules false --no-compress --format modern,cjs",
    ....
    },

Then in my tailwind file, I use

/*css/tailwind.css*/
@tailwind base;
@tailwind components;
@tailwind utilities;

In the Javascript file, just import the tailwind css file

// src/index.js

import React,{Fragment} from 'react';
import './css/tailwind.css';

export const ExampleComponent = ({ text }) => { 
  return (
  	<>
  	<div className ="example">
	 </div>
  	  </>
  	);
}

Make sure you have a tailwind.config.js with all the purge options set. This will help produce a minified build at production.

mklef121 avatar Dec 26 '20 15:12 mklef121

Would anyone show a full implementation of tailwind is CRL?

mohux avatar Feb 15 '21 10:02 mohux

Would anyone show a full implementation of tailwind is CRL?

@mohux Do you need a gist or can I post it here ?

mklef121 avatar Mar 30 '21 13:03 mklef121

Hello @ashleyisles I used tailwind with Create React Library. It was easy to use since microbundle uses rollup (Which uses a postcss plugin internally).

"scripts": {
    "build": "NODE_ENV=production microbundle-crl --no-compress --css-modules false --format modern,cjs",
    "start": "microbundle-crl watch --css-modules false --no-compress --format modern,cjs",
    ....
    },

Then in my tailwind file, I use

/*css/tailwind.css*/
@tailwind base;
@tailwind components;
@tailwind utilities;

In the Javascript file, just import the tailwind css file

// src/index.js

import React,{Fragment} from 'react';
import './css/tailwind.css';

export const ExampleComponent = ({ text }) => { 
  return (
  	<>
  	<div className ="example">
	 </div>
  	  </>
  	);
}

Make sure you have a tailwind.config.js with all the purge options set. This will help produce a minified build at production.

Hi, I'm following your modification, but I don't see the CSS bundled after building the package.

qnkhuat avatar Apr 26 '21 06:04 qnkhuat

oh, I forgot to add the postcss.config.js file. Now it's worked.

qnkhuat avatar Apr 26 '21 09:04 qnkhuat

Followed all the steps provided and getting this error even though postcss is v8.3.5 (postcss plugin) Error: PostCSS plugin tailwindcss requires PostCSS 8.

AsheshL avatar Jun 30 '21 20:06 AsheshL

I am using the compat version of tailwind for postcss v7 and it's working fine now

AsheshL avatar Jun 30 '21 20:06 AsheshL

oh, I forgot to add the postcss.config.js file. Now it's worked.

can you share the config please, it is not bundled in index.js

ahmedsayedabdelsalam avatar Sep 14 '21 16:09 ahmedsayedabdelsalam

@ahmedsayedabdelsalam Here is the project I got working I have linked the setup commit it's almost base so you can copy everything it uses typescript through github > react-real > setup.

rathod-sahaab avatar Sep 25 '21 20:09 rathod-sahaab

mmit it's almost base so you can co

Thanks for you response. I see in the example app you need to include the css bundle, not included in the js bundle image

ahmedsayedabdelsalam avatar Sep 25 '21 20:09 ahmedsayedabdelsalam