安裝
在 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": {}, },};
將 @import
新增至 ./assets/styles/app.css
,以匯入 Tailwind CSS。
@import "tailwindcss";
使用 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>