rsnext/examples/with-tailwindcss-emotion
NorbertLuszkiewicz c03d4931de
Simplify example usage instructions (#16678)
Co-authored-by: Joe Haddad <joe.haddad@zeit.co>
2020-08-29 22:22:02 -04:00
..
components [Example] update with-tailwindcss-emotion to tailwind 1.3.3 and emotion 11 + tailwind-ui plugin (#11611) 2020-04-24 18:27:43 -05:00
pages await ctx.renderPage() in examples for TypeScript (#15528) 2020-08-04 14:46:40 -04:00
styles Add CSS Modules examples to docs (#15601) 2020-07-29 14:43:48 +00:00
.babelrc [Example] update with-tailwindcss-emotion to tailwind 1.3.3 and emotion 11 + tailwind-ui plugin (#11611) 2020-04-24 18:27:43 -05:00
.gitignore Added .gitignore to examples that are deployed to vercel (#15127) 2020-07-16 10:52:23 -04:00
package.json Add CSS Modules examples to docs (#15601) 2020-07-29 14:43:48 +00:00
README.md Simplify example usage instructions (#16678) 2020-08-29 22:22:02 -04:00
tailwind.config.js [Example] update with-tailwindcss-emotion to tailwind 1.3.3 and emotion 11 + tailwind-ui plugin (#11611) 2020-04-24 18:27:43 -05:00

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

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

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