Production ready gatsby + tailwindcss setup.
Uses gatsby-plugin-postcss and gatsby-plugin-purgecss in combination with tailwindcss and autoprefixer.
Install Dependencies
npm install --save gatsby-plugin-postcss gatsby-plugin-purgecss autoprefixer tailwindcss
Generate tailwind config (optional)
npx tailwindcss init
Configure gatsby and PostCSS
In gatsby-config.js
:
module.exports = {// ...plugins: [// ...`gatsby-plugin-postcss`,{resolve: `gatsby-plugin-purgecss`,options: {printRejected: true,develop: false,tailwind: true// whitelist: [],// ignore: [],// purgeOnly : [],}}// ...]}
In postcss.config.js
:
module.exports = {plugins: [require("tailwindcss"), require("autoprefixer")]}
This setup will purge unused css classes in production (or on build) only.