rsnext/examples/with-tailwindcss-emotion/README.md
Joe Haddad 7d038dfef1
Suggest npx over npm init (#13637)
This updates old examples to the more universal `npx` command.

Fixes https://github.com/vercel/next.js/discussions/12103
2020-06-01 17:36:57 +00:00

2.3 KiB

Tailwind CSS with Emotion.js example

This is an example of how you can add tailwind CSS with Emotion.js in your web app. It takes inspiration from examples/with-tailwindcss.

@tailwindcssinjs/macro 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.

Deploy your own

Deploy the example using Vercel:

Deploy with Vercel

How to use

Using create-next-app

Execute create-next-app with npm or Yarn 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/vercel/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 Vercel (Documentation).

Notes

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;
}

tailwind CSS config

Use the following command when you add a tailwind plugin that adds to tailwind's base css:

npm run build:base-css
# or
yarn run build:base-css