This is an example of using Tailwind CSS in a Next.js project.
Deploy the example using ZEIT Now:
Execute create-next-app
with npm or Yarn to bootstrap the example:
npm init next-app --example with-tailwindcss with-tailwindcss-app
# or
yarn create next-app --example with-tailwindcss with-tailwindcss-app
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
Install it and run:
npm install
npm run dev
# or
yarn
yarn dev
Deploy it to the cloud with ZEIT Now (Documentation).
This setup is a basic starting point for using Tailwind CSS with Next.js. This example also includes the following PostCSS plugins:
- postcss-preset-env - Adds stage 2+ features and autoprefixes
- purgecss - Removes unused CSS
Purgecss takes a very straightforward approach to removing unused CSS. It simply searches an entire file for a string that matches a regular expression. As a result, class strings that are dynamically created in a template using string concatenation will be considered unused and removed from your stylesheet. Tailwind CSS addresses this problem in more detail in their documentation.