1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00
next.js/examples/with-tailwindcss
Michael Herold 5b3578e58f #4751 - Explicitly mention install when cloning examples (#4758)
Preferably this installation wouldn't be necessary, but in lieu of a fix...

#4751
2018-07-11 23:56:15 +02:00
..
components Fix linting 2017-11-25 12:03:25 +01:00
pages Fix linting 2017-11-25 12:03:25 +01:00
styles Upgrade standard.js (#4064) 2018-03-27 20:11:03 +02:00
package.json Update Next.js version on examples 2018-01-30 21:46:15 +01:00
README.md #4751 - Explicitly mention install when cloning examples (#4758) 2018-07-11 23:56:15 +02:00

Deploy to now

Tailwind CSS example

This is an example of how you can include a global stylesheet in a next.js webapp.

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 with-tailwindcss-app
# or
yarn create next-app --example with-tailwindcss with-tailwindcss-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
cd with-tailwindcss

Running

To get this example running you just need to

npm install
npm run dev
# or
yarn
yarn dev

Visit http://localhost:3000 and try to modify styles/index.css.

Deploy it to the cloud with now (download)

now

Extras

In the package.json you'll see some extra commands.

  • yarn dev:css
    • used by yarn dev generate css bundle and watch css files for changes
    • includes css imported into index.css
    • will not autoreload browser when css changes
  • yarn build:css
    • used by yarn build to generate css bundle

These can be used manually but using the usual commands will run them anyways.

The idea behind the example

This setup is a basic starting point for using tailwind css and next. Along with tailwind, this example also uses some other postcss plugins for imports, autoprefixing, and stripping whitespace/comments. The imports simply allow for an easy way to split up css files but still get one bundled css file in static/css/bundle.css. Changing stylesheets does not trigger auto-reloads. Setting up auto-reloads was avoided because the next.js read me does not recommend doing so. Although, that can easily be done with some webpack loaders. If you are curious about using loaders with next look at this example.

This project shows how you can set it up. Have a look at:

  • pages/_document.js
  • styles/config/postcss.config.js
  • styles/config/tailwind.config.js
  • styles/index.css
  • styles/button.css