Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/dev-warner/react-static-plugin-tailwindcss

A React-Static plugin that adds tailwindcss into your postcss plugins
https://github.com/dev-warner/react-static-plugin-tailwindcss

Last synced: 3 months ago
JSON representation

A React-Static plugin that adds tailwindcss into your postcss plugins

Awesome Lists containing this project

README

        

# A React-Static plugin that adds tailwind support

[![npm version](https://badge.fury.io/js/react-static-plugin-tailwindcss.svg)](https://badge.fury.io/js/react-static-plugin-tailwindcss)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

## Installation

In an existing react-static site run:

### Tailwind v2

```bash
$ yarn add react-static-plugin-tailwindcss tailwindcss@npm:@tailwindcss/postcss7-compat -D
```

### Tailwind v1

```bash
$ yarn add react-static-plugin-tailwindcss [email protected] -D
```

Then add the plugin to your static.config.js:

```js
export default {
plugins: ["react-static-plugin-tailwindcss"],
};
```

Now you can add @tailwind directives to your .css files

```css
@tailwind base;
@tailwind components;
@tailwind utilities;
```

### CSS-in-JS

If you're wanting to use tailwind in conjuction with styled-components for example

```bash
yarn add tailwind.macro@next
```

static.config.js

```js
export default {
plugins: [
[
"react-static-plugin-tailwindcss",
{
cssInJs: true,
},
],
],
};
```

Create a babel-plugin-macros.config.js file

```js
module.exports = {
tailwind: {
config: "./tailwind.config.js",
format: "auto",
},
};
```

Now you can use the tw macro inside styled components

```js
import tw from "tailwind.macro";
import styled from "styled-components";

export const Header = styled.h1`
${tw`text-4xl font-bold text-center text-blue-500`}
`;
```

### Autoprefixer

If you already handle auto prefixer or dont want to use it

```js
export default {
plugins: [
[
"react-static-plugin-tailwindcss",
{
autoPrefixer: false,
},
],
],
};
```