Installation
在 Gatsby 專案中設定 Tailwind CSS。
如果你還沒有設定專案,請先建立一個新的 Gatsby 專案。最常見的方式是使用 Gatsby CLI。
gatsby new my-projectcd my-project使用 npm 安裝 @tailwindcss/postcss、其對等相依套件,以及 gatsby-plugin-postcss。
npm install @tailwindcss/postcss tailwindcss postcss gatsby-plugin-postcss在你的 gatsby-config.js 檔案中,啟用 gatsby-plugin-postcss。請參閱 外掛文件以取得更多資訊。
module.exports = { plugins: [ 'gatsby-plugin-postcss', // ... ],}在專案根目錄建立 postcss.config.js 檔案,並將 @tailwindcss/postcss 外掛加入你的 PostCSS 設定。
module.exports = { plugins: { "@tailwindcss/postcss": {}, },};建立 ./src/styles/global.css 檔案,並加入 @import 來匯入 Tailwind CSS。
@import "tailwindcss";如果尚未存在,在專案根目錄建立 gatsby-browser.js 檔案,並匯入新建立的 ./src/styles/global.css 檔案。
import './src/styles/global.css';使用 gatsby develop 執行建置流程。
gatsby develop開始使用 Tailwind 的通用類別來設定內容樣式。
export default function IndexPage() { return ( <Layout> <h1 className="text-3xl font-bold underline"> Hello world! </h1> </Layout> )}