Installation
Thiết lập Tailwind CSS trong dự án Gatsby.
Bắt đầu bằng cách tạo một dự án Gatsby mới nếu bạn chưa thiết lập. Cách phổ biến nhất là sử dụng Gatsby CLI.
gatsby new my-projectcd my-projectSử dụng npm, cài đặt @tailwindcss/postcss, các peer dependencies, và gatsby-plugin-postcss.
npm install @tailwindcss/postcss tailwindcss postcss gatsby-plugin-postcssTrong file gatsby-config.js của bạn, bật gatsby-plugin-postcss. Xem tài liệu của plugin để biết thêm thông tin.
module.exports = { plugins: [ 'gatsby-plugin-postcss', // ... ],}Tạo file postcss.config.js ở thư mục gốc của dự án và thêm plugin @tailwindcss/postcss vào cấu hình PostCSS của bạn.
module.exports = { plugins: { "@tailwindcss/postcss": {}, },};Tạo file ./src/styles/global.css và thêm @import cho Tailwind CSS.
@import "tailwindcss";Tạo file gatsby-browser.js ở thư mục gốc của dự án nếu chưa có, và import file./src/styles/global.css vừa tạo.
import './src/styles/global.css';Chạy quá trình build với gatsby develop.
gatsby developBắt đầu sử dụng các utility class của Tailwind để style nội dung của bạn.
export default function IndexPage() { return ( <Layout> <h1 className="text-3xl font-bold underline"> Hello world! </h1> </Layout> )}