Installation
在 Symfony 專案中設定 Tailwind CSS。
如果你還沒有設定專案,請先建立一個新的 Symfony 專案。最常見的方式是使用 Symfony 安裝程式。
symfony new --webapp my-projectcd my-project安裝 Webpack Encore,它負責建置你的資源。請參閱 文件以取得更多資訊。
composer remove symfony/ux-turbo symfony/asset-mapper symfony/stimulus-bundlecomposer require symfony/webpack-encore-bundle symfony/ux-turbo symfony/stimulus-bundle使用 npm 安裝 @tailwindcss/postcss 及其對等相依套件,以及 postcss-loader。
npm install tailwindcss @tailwindcss/postcss postcss postcss-loader在你的 webpack.config.js 檔案中,啟用 PostCSS Loader。請參閱 文件以取得更多資訊。
Encore .enablePostCssLoader();在專案根目錄建立 postcss.config.mjs 檔案,並將 @tailwindcss/postcss 外掛加入你的 PostCSS 設定。
export default { plugins: { "@tailwindcss/postcss": {}, },};在 ./assets/styles/app.css 中加入 @import 來匯入 Tailwind CSS,並加入 @source 來忽略 public 目錄,以防止在監視模式下重複編譯。
@import "tailwindcss";@source not "../../public";使用 npm run watch 執行建置流程。
npm run watch確保你編譯後的 CSS 已包含在 <head> 中,然後開始使用 Tailwind 的通用類別來設定內容樣式。
<!doctype html><html> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> {% block stylesheets %} {{ encore_entry_link_tags('app') }} {% endblock %} </head> <body> <h1 class="text-3xl font-bold underline"> Hello world! </h1> </body></html>