rsnext/examples/with-tailwindcss-emotion
Arthur Petrie 453adc6864
[Examples] update with-tailwindcss-emotion to tailwind 2.0 (#19476)
Hello, this PR updates the with-tailwindcss-emotion example to be compatible with tailwindcss 2.0

Here is a summary of all the changes:
- update `.babelrc` config
- update `README.md`
- delete `@emotion/css component` (makes the example simpler)
- update `@emotion/react` component to use xwind
- update `@emotion/styled` component to use xwind
- Add global styles to `_app.js`
- remove `_document.js` page
- remove `base.css` global style files (global styles are added in _app.js)
- update `tailwind.config.js`
- update `package.json` dependencies + remove unnecessary `build:base-css` script
2020-11-25 18:17:12 +00:00
..
components [Examples] update with-tailwindcss-emotion to tailwind 2.0 (#19476) 2020-11-25 18:17:12 +00:00
pages [Examples] update with-tailwindcss-emotion to tailwind 2.0 (#19476) 2020-11-25 18:17:12 +00:00
styles [Examples] update with-tailwindcss-emotion to tailwind 2.0 (#19476) 2020-11-25 18:17:12 +00:00
.babelrc [Examples] update with-tailwindcss-emotion to tailwind 2.0 (#19476) 2020-11-25 18:17:12 +00:00
.gitignore Added .gitignore to examples that are deployed to vercel (#15127) 2020-07-16 10:52:23 -04:00
package.json [Examples] update with-tailwindcss-emotion to tailwind 2.0 (#19476) 2020-11-25 18:17:12 +00:00
README.md [Examples] update with-tailwindcss-emotion to tailwind 2.0 (#19476) 2020-11-25 18:17:12 +00:00
tailwind.config.js [Examples] update with-tailwindcss-emotion to tailwind 2.0 (#19476) 2020-11-25 18:17:12 +00: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.

xwind 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(xw`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