Installation
Setting up Tailwind CSS in a Symfony project.
Start by creating a new Symfony project if you don’t have one set up already. The most common approach is to use the Symfony Installer.
symfony new --webapp my-projectcd my-projectInstall Webpack Encore, which handles building your assets. See the documentation for more information.
composer remove symfony/ux-turbo symfony/asset-mapper symfony/stimulus-bundlecomposer require symfony/webpack-encore-bundle symfony/ux-turbo symfony/stimulus-bundleUsing npm, install @tailwindcss/postcss and its peer dependencies, as well as postcss-loader.
npm install tailwindcss @tailwindcss/postcss postcss postcss-loaderIn your webpack.config.js file, enable the PostCSS Loader. See the documentation for more information.
Encore .enablePostCssLoader();Create a postcss.config.mjs file in the root of your project and add the @tailwindcss/postcss plugin to your PostCSS configuration.
export default { plugins: { "@tailwindcss/postcss": {}, },};Add an @import to ./assets/styles/app.css that imports Tailwind CSS and an @source that ignores the public dir to prevent recompile loops in watch mode.
@import "tailwindcss";@source not "../../public";Run your build process with npm run watch.
npm run watchMake sure your compiled CSS is included in the <head> then start using Tailwind’s utility classes to style your content.
<!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>Tailwind CSS 中文网(本网站)的目标是为中文开发者提供准确、及时的 Tailwind CSS 中文文档
Tailwind CSS 中文文档由本网站维护人员共同翻译,采用 MIT 开源协议发布
本网站与 tailwindcss.com 及 Tailwind Labs Inc. 并无从属关系
Tailwind 商标由 Tailwind Labs Inc. 所有
京ICP备15031610号-106