rsnext/examples/with-tailwindcss-emotion
Joe Haddad 18a9c7e371
Improve linting rules to catch more errors (#9374)
* Update `packages/`

* Update examples

* Update tests

* Update bench

* Update top level files

* Fix build

* trigger
2019-11-10 19:24:53 -08:00
..
pages Improve linting rules to catch more errors (#9374) 2019-11-10 19:24:53 -08:00
.babelrc Add the example of Tailwind CSS with emotion (#8931) 2019-10-16 22:51:53 -05:00
babel-plugin-macros.config.js Improve linting rules to catch more errors (#9374) 2019-11-10 19:24:53 -08:00
next.config.js Improve linting rules to catch more errors (#9374) 2019-11-10 19:24:53 -08:00
package.json Add the example of Tailwind CSS with emotion (#8931) 2019-10-16 22:51:53 -05:00
README.md Add the example of Tailwind CSS with emotion (#8931) 2019-10-16 22:51:53 -05:00
tailwind.js Improve linting rules to catch more errors (#9374) 2019-11-10 19:24:53 -08:00

Tailwind CSS with Emotion.js example

This is an example of how you can add the tailwind CSS with Emotion.js in your web app.

How to use

Using create-next-app

Execute create-next-app with Yarn or npx to bootstrap the example:

npx create-next-app --example with-tailwindcss-emotion with-tailwindcss-emotion-app
# or
yarn create next-app --example with-tailwindcss-emotion with-tailwindcss-emotion-app

Download manually

Download the example:

curl https://codeload.github.com/zeit/next.js/tar.gz/canary | tar -xz --strip=2 next.js-canary/examples/with-tailwindcss-emotion
cd with-tailwindcss-emotion

Install it and run:

npm install
npm run dev
# or
yarn
yarn dev

Deploy it to the cloud with now (download):

now

The idea behind the example

This setup has inspiration from examples/with-tailwindcss. This example will show you how to integrate Emotion with tailwind.

tailwindcss.macros is used to add tailwind classes inside Emotion by injecting the tailwind CSS into the styled component. No need to use CSS files, autoprefix, minifier, etc. You will get the full benefits of Emotion.

The CSS classes generated by Emotion will include the tailwind styles but not the name of the classes. For example the following component:

const Header = styled.div`
  ${tw`font-mono text-sm text-gray-800`}
`

Will be transformed into:

.css-25og8s-Header {
  font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New',
    monospace;
  font-size: 0.875rem;
  color: #2d3748;
}