2017-11-23 12:48:34 +00:00
[![Deploy to now ](https://deploy.now.sh/static/button.svg )](https://deploy.now.sh/?repo=https://github.com/zeit/next.js/tree/master/examples/with-tailwindcss)
# Tailwind CSS example
This is an example of how you can include a global stylesheet in a next.js webapp.
## How to use
2017-12-03 04:30:17 +00:00
### Using `create-next-app`
2018-04-03 12:19:05 +00:00
Execute [`create-next-app` ](https://github.com/segmentio/create-next-app ) with [Yarn ](https://yarnpkg.com/lang/en/docs/cli/create/ ) or [npx ](https://github.com/zkat/npx#readme ) to bootstrap the example:
2017-12-03 04:30:17 +00:00
2018-03-14 08:09:46 +00:00
```bash
npx create-next-app --example with-tailwindcss with-tailwindcss-app
# or
yarn create next-app --example with-tailwindcss with-tailwindcss-app
2017-12-03 04:30:17 +00:00
```
### Download manually
2017-11-23 12:48:34 +00:00
Download the example [or clone the repo ](https://github.com/zeit/next.js ):
```bash
2017-12-07 02:12:42 +00:00
curl https://codeload.github.com/zeit/next.js/tar.gz/canary | tar -xz --strip=2 next.js-canary/examples/with-tailwindcss
2017-11-23 12:48:34 +00:00
cd with-tailwindcss
```
**Running**
To get this example running you just need to
2018-04-03 12:19:05 +00:00
```bash
npm install
npm run dev
# or
yarn
yarn dev
```
2017-11-23 12:48:34 +00:00
Visit [http://localhost:3000 ](http://localhost:3000 ) and try to modify `styles/index.css` .
Deploy it to the cloud with [now ](https://zeit.co/now ) ([download](https://zeit.co/download))
```bash
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 ](https://github.com/zeit/next.js/tree/canary/examples/with-global-stylesheet ).
This project shows how you can set it up. Have a look at:
2018-04-03 12:19:05 +00:00
* pages/\_document.js
2017-11-23 12:48:34 +00:00
* styles/config/postcss.config.js
* styles/config/tailwind.config.js
* styles/index.css
* styles/button.css