¿Qué pasa con el CSS? Eres libre de añadir el CSS que quieras a app/styles/app.css. Ese archivo ya está cargado en la página.
¿Quieres utilizar CSS de Bootstrap? Consulta la documentación de Asset Mapper sobre cómo hacerlo. O, si quieres usar Sass, hay un symfonycasts/sass-bundle que te lo pone fácil. No obstante, te recomiendo que no te lances a usar Sass demasiado rápido, ya que muchas de las funciones por las que Sass es famoso pueden hacerse ahora en CSS nativo, como las variables CSS e incluso el anidamiento CSS.
Hola Tailwind
¿Cuál es mi elección personal para un framework CSS? Tailwind. Y parte de la razón es que Tailwind es increíblemente popular. Así que si buscas recursos o componentes preconstruidos, vas a tener mucha suerte si utilizas Tailwind.
Pero Tailwind es un poco extraño en un sentido: no es simplemente un gran archivo CSS que pones en tu página. En su lugar, tiene un proceso de construcción que escanea tu código en busca de todas las clases Tailwind que estés utilizando. Luego vuelca un archivo CSS final que sólo contiene el código que necesitas.
En el mundo Symfony, si quieres utilizar Tailwind, hay un bundle que lo hace realmente fácil. Gira tu terminal e instala un nuevo paquete: composer require symfonycasts - hey los conozco - tailwind-bundle:
composer require symfonycasts/tailwind-bundle
Para este paquete, la receta no hace nada más que activar el nuevo bundle. Para poner en marcha Tailwind, una vez en tu proyecto, ejecuta:
php bin/console tailwind:init
Esto hace tres cosas. En primer lugar, descarga un binario de Tailwind en segundo plano, algo en lo que nunca tendrás que pensar. En segundo lugar, crea un archivo tailwind.config.jsen la raíz de nuestro proyecto. Esto indica a Tailwind dónde tiene que buscar en nuestro proyecto las clases CSS de Tailwind. Y tercero, actualiza nuestro app.css para añadir estas tres líneas. Éstas serán sustituidas por el código real de Tailwind en segundo plano por el binario.
Ejecutar Tailwind
Por último, hay que compilar Tailwind, así que tenemos que ejecutar un comando para hacerlo:
php bin/console tailwind:build -w
Esto escanea nuestras plantillas y genera el archivo CSS final en segundo plano. El -w lo pone en modo "vigilar": en lugar de construir una vez y salir, vigila nuestras plantillas en busca de cambios. Cuando detecte alguna actualización, reconstruirá automáticamente el archivo CSS. Lo veremos en un minuto.
Pero ya deberíamos ver una diferencia. Vamos a la página de inicio. ¿Lo has visto? El código base de Tailwind ha hecho un reinicio. Por ejemplo, ¡nuestro h1 es ahora diminuto!
Ver Tailwind en acción
Probemos esto de verdad. Abre templates/main/homepage.html.twig. Encima de h1, hazlo más grande añadiendo una clase: text-2xl.
| // ... lines 1 - 4 | |
| {% block body %} | |
| <h1 class="text-2xl"> | |
| Starshop: your monopoly-busting option for Starship parts! | |
| </h1> | |
| // ... lines 9 - 46 | |
| {% endblock %} |
En cuanto guardemos eso, podrás ver que tailwind se dio cuenta de nuestro cambio y reconstruyó el CSS. Y cuando actualizamos, ¡se hizo más grande!
Nuestro archivo fuente app.css sigue siendo super sencillo: sólo esas pocas líneas que vimos antes. Pero mira el código fuente de la página y abre el app.css que se está enviando a nuestros usuarios. ¡Es la versión construida de Tailwind! Entre bastidores, existe cierta magia que sustituye esas tres líneas de Tailwind por el código CSS real de Tailwind.
Ejecutar automáticamente Tailwind con el binario symfony
Y... ¡eso es todo! Simplemente funciona. Aunque hay una forma más fácil y automática de ejecutar Tailwind. Pulsa Ctrl+C en el comando Tailwind para detenerlo. A continuación, en la raíz de nuestro proyecto, crea un archivo llamado .symfony.local.yaml. Se trata de un archivo de configuración para el servidor web binario symfony que estamos utilizando. Dentro, añade workers, tailwind, y luego cmd configurados en una matriz con cada parte de un comando: symfony, console, tailwind, build, --watch, o podrías utilizar -w: es lo mismo.
Aún no he hablado de ello, pero en lugar de ejecutar php bin/console, también podemos ejecutar symfony console seguido de cualquier comando para obtener el mismo resultado. Hablaremos de por qué te conviene hacerlo en un futuro tutorial. Pero por ahora, considera que bin/console y symfony console son lo mismo.
Además, al añadir esta clave workers, significa que en lugar de que tengamos que ejecutar el comando manualmente, cuando iniciemos el servidor web symfony, éste lo ejecutará por nosotros en segundo plano.
Observa. En tu primera pestaña, pulsa Ctrl+C para detener el servidor web... luego vuelve a ejecutar
symfony serve
para que vea el nuevo archivo de configuración. Mira: ¡ahí está! ¡Está ejecutando el comando tailwind en segundo plano!
Podemos aprovecharnos de esto inmediatamente. En homepage.html.twig, cambia esto atext-4xl, gira y... ¡funciona! Ya ni siquiera tenemos que pensar en el comandotailwind:build.
| // ... lines 1 - 4 | |
| {% block body %} | |
| <h1 class="text-4xl"> | |
| Starshop: your monopoly-busting option for Starship parts! | |
| </h1> | |
| // ... lines 9 - 46 | |
| {% endblock %} |
Y como estilizaremos con Tailwind, elimina el fondo azul.
Copiar en plantillas estilizadas
Vale, este tutorial no trata sobre Tailwind ni sobre cómo diseñar un sitio web. Créeme, no quieres que Ryan dirija la carga del diseño web. Pero sí quiero tener un sitio bonito... y también es importante pasar por el proceso de trabajar con un diseñador.
Así que imaginemos que otra persona ha creado un diseño para nuestro sitio. E incluso nos han dado algo de HTML con clases de Tailwind para ese diseño. Si descargas el código del curso, en un directorio de tutorial/templates/, tenemos 3 plantillas. Uno a uno, voy a copiar cada archivo y pegarlo sobre el original. No te preocupes, veremos lo que ocurre en cada uno de estos archivos.
| <html> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <title>{% block title %}Welcome!{% endblock %}</title> | |
| <link rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 128 128%22><text y=%221.2em%22 font-size=%2296%22>⚫️</text></svg>"> | |
| {% block stylesheets %} | |
| {% endblock %} | |
| {% block javascripts %} | |
| {% block importmap %}{{ importmap('app') }}{% endblock %} | |
| {% endblock %} | |
| </head> | |
| <body class="text-white" style="background: radial-gradient(102.21% 102.21% at 50% 28.75%, #00121C 42.62%, #013954 100%);"> | |
| <div class="flex flex-col justify-between min-h-screen relative"> | |
| <div> | |
| <header class="h-[114px] shrink-0 flex flex-col sm:flex-row items-center sm:justify-between py-4 sm:py-0 px-6 border-b border-white/20 shadow-md"> | |
| <a href="#"> | |
| <img class="h-[42px]" src="{{ asset('images/starshop-logo.png') }}" alt="starshop logo"> | |
| </a> | |
| <nav class="flex space-x-4 font-semibold"> | |
| <a class="hover:text-amber-400 pt-2" href="#"> | |
| Home | |
| </a> | |
| <a class="hover:text-amber-400 pt-2" href="#"> | |
| About | |
| </a> | |
| <a class="hover:text-amber-400 pt-2" href="#"> | |
| Contact | |
| </a> | |
| <a class="rounded-[60px] py-2 px-5 bg-white/10 hover:bg-white/20" href="#"> | |
| Get Started | |
| </a> | |
| </nav> | |
| </header> | |
| {% block body %}{% endblock %} | |
| </div> | |
| <div class="p-5 bg-white/5 mt-3 text-center"> | |
| Made with ❤️ by <a class="text-[#0086C4]" href="https://symfonycasts.com">SymfonyCasts</a> | |
| </div> | |
| </div> | |
| </body> | |
| </html> |
Haz homepage.html.twig...
| {% extends 'base.html.twig' %} | |
| {% block title %}Starshop: Beam up some parts!{% endblock %} | |
| {% block body %} | |
| <main class="flex flex-col lg:flex-row"> | |
| <aside | |
| class="pb-8 lg:pb-0 lg:w-[411px] shrink-0 lg:block lg:min-h-screen text-white transition-all overflow-hidden px-8 border-b lg:border-b-0 lg:border-r border-white/20" | |
| > | |
| <div class="flex justify-between mt-11 mb-7"> | |
| <h2 class="text-[32px] font-semibold">My Ship Status</h2> | |
| <button> | |
| <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 448 512"><!--!Font Awesome Pro 6.5.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2024 Fonticons, Inc.--><path fill="#fff" d="M384 96c0-17.7 14.3-32 32-32s32 14.3 32 32V416c0 17.7-14.3 32-32 32s-32-14.3-32-32V96zM9.4 278.6c-12.5-12.5-12.5-32.8 0-45.3l128-128c12.5-12.5 32.8-12.5 45.3 0s12.5 32.8 0 45.3L109.3 224 288 224c17.7 0 32 14.3 32 32s-14.3 32-32 32l-178.7 0 73.4 73.4c12.5 12.5 12.5 32.8 0 45.3s-32.8 12.5-45.3 0l-128-128z"/></svg> | |
| </button> | |
| </div> | |
| <div> | |
| <div class="flex flex-col space-y-1.5"> | |
| <div class="rounded-2xl py-1 px-3 flex justify-center w-32 items-center" style="background: rgba(255, 184, 0, .1);"> | |
| <div class="rounded-full h-2 w-2 bg-amber-400 blur-[1px] mr-2"></div> | |
| <p class="uppercase text-xs">in progress</p> | |
| </div> | |
| <h3 class="tracking-tight text-[22px] font-semibold"> | |
| <a class="hover:underline" href="{{ path('app_starship_show', { | |
| id: myShip.id | |
| }) }}">{{ myShip.name }}</a> | |
| </h3> | |
| </div> | |
| <div class="flex mt-4"> | |
| <div class="border-r border-white/20 pr-8"> | |
| <p class="text-slate-400 text-xs">Captain</p> | |
| <p class="text-xl">{{ myShip.captain }}</p> | |
| </div> | |
| <div class="pl-8"> | |
| <p class="text-slate-400 text-xs">Class</p> | |
| <p class="text-xl">{{ myShip.class }}</p> | |
| </div> | |
| </div> | |
| </div> | |
| </aside> | |
| <div class="px-12 pt-10 w-full"> | |
| <h1 class="text-4xl font-semibold mb-8"> | |
| Ship Repair Queue | |
| </h1> | |
| <div class="space-y-5"> | |
| <!-- start ship item --> | |
| <div class="bg-[#16202A] rounded-2xl pl-5 py-5 pr-11 flex flex-col min-[1174px]:flex-row min-[1174px]:justify-between"> | |
| <div class="flex justify-center min-[1174px]:justify-start"> | |
| <img class="h-[83px] w-[84px]" src="/images/status-in-progress.png" alt="Status: in progress"> | |
| <div class="ml-5"> | |
| <div class="rounded-2xl py-1 px-3 flex justify-center w-32 items-center bg-amber-400/10"> | |
| <div class="rounded-full h-2 w-2 bg-amber-400 blur-[1px] mr-2"></div> | |
| <p class="uppercase text-xs text-nowrap">in progress</p> | |
| </div> | |
| <h4 class="text-[22px] pt-1 font-semibold"> | |
| <a | |
| class="hover:text-slate-200" | |
| href="#" | |
| >USS LeafyCruiser</a> | |
| </h4> | |
| </div> | |
| </div> | |
| <div class="flex justify-center min-[1174px]:justify-start mt-2 min-[1174px]:mt-0 shrink-0"> | |
| <div class="border-r border-white/20 pr-8"> | |
| <p class="text-slate-400 text-xs">Captain</p> | |
| <p class="text-xl">Jean-Luc Pickles</p> | |
| </div> | |
| <div class="pl-8 w-[100px]"> | |
| <p class="text-slate-400 text-xs">Class</p> | |
| <p class="text-xl">Garden</p> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- end ship item --> | |
| </div> | |
| <p class="text-lg mt-5 text-center md:text-left"> | |
| Looking for your next galactic ride? | |
| <a href="#" class="underline font-semibold">Browse the {{ ships|length * 10 }} starships for sale!</a> | |
| </p> | |
| </div> | |
| </main> | |
| {% endblock %} |
y finalmente show.html.twig.
| {% extends 'base.html.twig' %} | |
| {% block title %}{{ ship.name }}{% endblock %} | |
| {% block body %} | |
| <div class="my-4 px-8"> | |
| <a class="bg-white hover:bg-gray-200 rounded-xl p-2 text-black" href="#"> | |
| <svg class="inline text-black" xmlns="http://www.w3.org/2000/svg" height="16" width="14" viewBox="0 0 448 512"><!--!Font Awesome Free 6.5.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--><path fill="#000" d="M9.4 233.4c-12.5 12.5-12.5 32.8 0 45.3l160 160c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3L109.2 288 416 288c17.7 0 32-14.3 32-32s-14.3-32-32-32l-306.7 0L214.6 118.6c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0l-160 160z"/></svg> | |
| Back | |
| </a> | |
| </div> | |
| <div class="md:flex justify-center space-x-3 mt-5 px-4 lg:px-8"> | |
| <div class="flex justify-center"> | |
| <img class="max-h-[300px] md:max-h-[500px]" src="{{ asset('images/purple-rocket.png') }}" alt="purple ship launching"> | |
| </div> | |
| <div class="space-y-5"> | |
| <div class="mt-8 max-w-xl mx-auto"> | |
| <div class="px-8 pt-8"> | |
| <div class="rounded-2xl py-1 px-3 flex justify-center w-32 items-center bg-amber-400/10"> | |
| <div class="rounded-full h-2 w-2 bg-amber-400 blur-[1px] mr-2"></div> | |
| <p class="uppercase text-xs">{{ ship.status }}</p> | |
| </div> | |
| <h1 class="text-[32px] font-semibold border-b border-white/10 pb-5 mb-5"> | |
| {{ ship.name }} | |
| </h1> | |
| <h4 class="text-xs text-slate-300 font-semibold mt-2 uppercase">Spaceship Captain</h4> | |
| <p class="text-[22px] font-semibold">{{ ship.captain }}</p> | |
| <h4 class="text-xs text-slate-300 font-semibold mt-2 uppercase">Class</h4> | |
| <p class="text-[22px] font-semibold">{{ ship.class }}</p> | |
| <h4 class="text-xs text-slate-300 font-semibold mt-2 uppercase">Ship Status</h4> | |
| <p class="text-[22px] font-semibold">30,000 lys to next service</p> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| {% endblock %} |
Tip
Si copias los archivos (en lugar del contenido de los archivos), puede que el sistema de caché de Symfony no note el cambio y no veas el nuevo diseño. Si eso ocurre, borra la caché ejecutando php bin/console cache:clear.
Voy a borrar por completo el directorio tutorial/ para no confundirme y editar las plantillas equivocadas.
Vale, ¡vamos a ver qué ha hecho esto! Actualizar. ¡Tiene un aspecto precioso! Me encanta trabajar dentro de un diseño bonito. Pero... algunas partes están rotas. En homepage.html.twig, ésta es nuestra cola de reparación de barcos... que queda muy bien... ¡pero no hay código Twig! El estado está codificado, el nombre está codificado y no hay bucle.
| // ... lines 1 - 4 | |
| {% block body %} | |
| <main class="flex flex-col lg:flex-row"> | |
| // ... lines 7 - 42 | |
| <div class="px-12 pt-10 w-full"> | |
| <h1 class="text-4xl font-semibold mb-8"> | |
| Ship Repair Queue | |
| </h1> | |
| <div class="space-y-5"> | |
| <!-- start ship item --> | |
| <div class="bg-[#16202A] rounded-2xl pl-5 py-5 pr-11 flex flex-col min-[1174px]:flex-row min-[1174px]:justify-between"> | |
| <div class="flex justify-center min-[1174px]:justify-start"> | |
| <img class="h-[83px] w-[84px]" src="/images/status-in-progress.png" alt="Status: in progress"> | |
| <div class="ml-5"> | |
| <div class="rounded-2xl py-1 px-3 flex justify-center w-32 items-center bg-amber-400/10"> | |
| <div class="rounded-full h-2 w-2 bg-amber-400 blur-[1px] mr-2"></div> | |
| <p class="uppercase text-xs text-nowrap">in progress</p> | |
| </div> | |
| <h4 class="text-[22px] pt-1 font-semibold"> | |
| <a | |
| class="hover:text-slate-200" | |
| href="#" | |
| >USS LeafyCruiser</a> | |
| </h4> | |
| </div> | |
| </div> | |
| <div class="flex justify-center min-[1174px]:justify-start mt-2 min-[1174px]:mt-0 shrink-0"> | |
| <div class="border-r border-white/20 pr-8"> | |
| <p class="text-slate-400 text-xs">Captain</p> | |
| <p class="text-xl">Jean-Luc Pickles</p> | |
| </div> | |
| <div class="pl-8 w-[100px]"> | |
| <p class="text-slate-400 text-xs">Class</p> | |
| <p class="text-xl">Garden</p> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- end ship item --> | |
| </div> | |
| // ... lines 80 - 84 | |
| </div> | |
| </main> | |
| {% endblock %} |
A continuación: tomemos nuestro nuevo diseño y hagámoslo dinámico. También aprenderemos a organizar las cosas en parciales de plantilla e introduciremos un enum PHP, que son divertidos.
62 Comments
Hi guys, just a note for people using Windows and WSL.
I had issues with hot reload which I solved using this thread and simply moving the project from
/mnt/c/path/to/repoto/home/user/path/to/repodid the following:php bin/console tailwind:build --watchactually rebuilds when I change a twig fileHey Andrei,
Thanks for sharing these tips to our Windows friends :) I like your performance boost also, sounds great!
Cheers!
How do you auto run the watcher in a docker container when you start the container with docker compose up? I'm using this https://github.com/dunglas/symfony-docker
Hey @sfr
That's a great question. I think you can do what they say in this post https://github.com/dunglas/symfony-docker/issues/475#issuecomment-3634160207
define the command in the
tailwindcontainerCheers~
Hello there,
For all like me struggling with tailwind not working as expected since V4 :
Do not downgrade tailwind, adapt the app.css like :
@tailwind base;@tailwind components;@tailwind utilities;@import "tailwindcss";You can see this on this official page : https://tailwindcss.com/docs/upgrade-guide#removed-tailwind-directives
Thanks @Symio!
I think the
init commandshould bootstrap you correctly based on which version of tailwind you have. However our code download for the course has the v3 init code: so if you update to a v4 insymfonycasts_tailwind.yaml, you'll have issues.I appreciate your comment.
Cheers!
Anyone else encounter this error when running
symfony serveafter installing tailwind?Browserslist: caniuse-lite is outdated. Please run:{"level":"debug","source":"runner","cmd":"tailwind","time":"2025-04-17T11:25:13+08:00","message":"Received timer message (first boot)"}Hey Skribe,
That's fine. You only need to update
caniuse-liteif it's actually causing you troubles, otherwise, just ignore it.To update it, you can run
yarn update-browserslist-db --updateCheers!
Hi all!
I'm having trouble getting Tailwind CSS autocompletion to work in PHPStorm for my Twig templates. I've searched everywhere in the settings but can't get it to work properly.
Could someone help me set up Tailwind CSS autocompletion correctly in PHPStorm for Twig files?
Thanks in advance for your help!
Hey Simston!
Sorry for my super late reply, I missed your message somehow. Perhaps you already solved your problem but here's a list of things you can try (I got it from ChatGPT, but went through it and looks good to me)
Install the Tailwind CSS plugin
Enable Tailwind CSS for your project
After plugin installation:
⚠️ Warning: this step may cause false positives or issues with Twig-specific syntax, so use it only if you're okay with treating Twig as HTML.
I hope it helps. Cheers!
Read that symfony doesn't currently support tailwind 4.*
I'm thinking of trying few things i read online and in forums to fix it. Anyways, it brings another question I just can't seem to google out:
How do I uninstall any particular(bundle,package, or whatever they are called) from my project ? In this case tailwind, with all the related files.
Hey @John-S,
Tailwind 4 support is coming soon: https://github.com/SymfonyCasts/tailwind-bundle/pull/91
composer remove the/packageremoves the actual package but there might be some things left - each bundle is different. You may need to manually remove the bundle and config. In the case of tailwind-bundle, you'd need to remove some stuff from your css file.Hi, I got into trouble with the
tailwind:initcommand.The moment I call it, something like Windows Smart-screen pops up and refuses to run the application: https://ibb.co/wFzXWv8m
In translation it says something like: "This app can't run on your computer".
I then see this in the console, translated as something like: "Access denied. [ERROR] Tailwind CSS init failed: see output above"
Even if I turn off antivirus, even if I turn off everything in Windows around security, no change.
Any clue?
Hey Ondrej,
It's difficult to say for me because I don't use Windows.. but it should work on Windows as well. Probably some problems specific to your computer. I would recommend you try to install the Tailwind yourself and try its binary to see it works well. Then just point the bundle to the binary you installed, see the docs how to do it: https://symfony.com/bundles/TailwindBundle/current/index.html#using-a-different-binary
It's more like a workaround, but I hope that helps this way.
Cheers!
I tried the "Using a different binary", but no matter I write to the config it seems it doesn't matter. Like the error fires up before even get there.
I did some debugging to see, where it happens and it's right here:
\Symfonycasts\TailwindBundle\Command\TailwindInitCommand::createTailwindConfigon line 61When I go to the wait function
\Symfony\Component\Process\Process::waitit happens right in the do/while block on the line 453.The error triggers the code
$this->readPipes($running, '\\' !== \DIRECTORY_SEPARATOR || !$running);, not the previous ones.But funny is - the code gets to the
readPipesmethod, can run twice and after that it shows the error. It's like the system doesn't min the method itself, but rather the fact it runs in cycles and stops it after a while.Can you see something suspicious there?
Hey Ondrej,
Hm, really not sure... It sounds like you're having trouble with the binary on your computer. The best option would be to try to google how to install Tailwind correctly on your specific platform. After you install it properly - try to run the installed binary directly. The idea is if that will work for your platform directly, it should also work for you with the bundle.
Cheers!
Ok I think a solved the problem. It was actually two problems, one hiding behind the other one.
All the Windows errors "This app can't run on your computer" was because when the commands tried to run the tailwind client in
var/tailwind/v3.4.17, they actually tried to run an exe file with zero size. Just an empty file. And for some reason in Windows the error looks like that.So what was the original problem? Why was there such a broken file?
When I initially run the
tailwind:init, my "awesome" antivir AvastOne was so eager to make false/positive detection, it apparently blocked downloading the file in this most terrible way - not saying anything a creating the file but empty. I actually had more problems with the Avast in last days - I had to whitelist all urls important for devs, like github, packagist etc, because I wasn't even able to run normalcomposer installcommand.The funny thing was, that I of course tried to turn of the antivir and even uninstall it, but every time I tried your steps from the beginning, the
tailwind:initnever tried to override the broken cli. It just checked it's there and thought "Ok, I'll just use it".I finally tried to delete all the files and now, the
initcommand worked because new antivir didn't the downloading.So I just wanted to describe it and maybe help someone in the future.
The most funny thing? I don't even wanna use Tailwind, I don't like the way it work and I prefer clean HTML structure and I was able to easily continue the lessons without it :D
But thank you Victor for your effort.
Hi Ondrej-Vasicek. I've been facing the same
This app can't run on your PCerror when I try to runphp bin/console tailwind:buildcommand. So I'd kindly like to know how did you solve this issue.Hi, I've described it in the previous post - in a nutshell - antivir program blocked creating proper exe file and created only empty file. When executing empty file, Windows has this error message. So the solution was to (unfortunately) change my antivir and start the proces over again, so the exe file was created/downloaded again properly. More info in the previous post.
Hey Ondrej,
Happy to hear you found the problem! Yeah, that makes sense, the bundle does not override if the file exists and no any sum checks on the existent file for some performance reasons. So you just need to manually drop that corrupted file.
Thanks for sharing the solution with others, I think most Windows users may face this problem, so it should be useful to them for sure.
Cheers!
Just ran into the same issue with Windows Defender (1.1.25080.5) on Windows 10 22H2 with PHP 8.4, Symfony 7.3 and TailwindCSS 4.
Temporary solution
Removing the bundle via composer, disabling Defender and reinstalling the bundle, and running
initagain and then thebuildcommand "fixed it for now." What I noticed was that theinitcommand didn't download the executable, but thebuildcommand did.I saw there is a closed issue [98] on this in the GitHub repository with a "fix." But as this at least partially is playing into antivirus behavior, it seems like it should be looked into further, my assumption out of the blue is that Defender (and probably other AVs too) doesn't want to play nice with downloading the executable here for some reason (a common way of backloading malware), and that then results in the 0-byte file, which throws the SmartScreen error when it's attempted to be executed with the
buildcommand. If that would be the case, my guess is thatdownloadExecutable()is to blame, but I sadly don't have a "permanent fix" for this issue.Hey Taminoful,
Thanks for sharing your working solution with others! Hm, indeed some antiviruses may case issues with downloading executable, probably depends on the antivirus config. I'm not sure if we can do much with it, moreover I'm not on wondows so it's harder to reproduce for me. But if you say it creates an empty file - that may lead to not clear error I suppose. I'm not sure if we should check the file size and throw if it's empty, not sure if there's a better way to check for file corruption in this case. If you have some ideas how to improve or make the process more robust - please, feel free to send a PR or open an issue to discuss first.
Cheers!
Hey there Victor,
I've gone ahead and opened an issue for discussing potential fixes for this issue, recapping the situation on the repo now. I'll help out and brainstorm solutions as much as my time allows me to, went ahead and proposed some solutions in there too.
Happy to help! :)
Hey Taminoful,
Awesome, thanks for opening the issue on it! And thanks for helping with brainstorming the solutions ❤️
Cheers!
For anyone still reading down this far, this is what I had to do to resolve the "PC cannot run app" error when I ran the command "php bin/console tailwind:build -w". As described by "Ondrej-Vasicek" my Windows11 Defender blocked the download in the most unhelpful way and ".exe" file was size 0kbs. When I ran the build command with the additional flag "-v" I could see the url for the file that was "blocked" as "https://github.com/tailwindlabs/tailwindcss/releases/download/v4.1.11/tailwindcss-windows-x64.exe " (Your url may be different depending on your tailwind version)
I put this into my browser (chrome) and the exe was downloaded without an issue. No idea why.
I then put the downloaded exe into the directory "[project_name]/var/tailwind/v[version_number]/". You many need to delete or replace the empty exe if it is still there. I was able to continue the tutorial from there.
Hope this helps.
Note that I did try a few ways to disable/work-around Win11 Defender but they did not help me.
Hey Ben,
Thanks for sharing your solution. Yeah, it's weird that the file is not blocked when you download it from the browser, probably some trustworthy user interaction, I'm not sure. Well, as always, Windows has its own quirks :)
Cheers!
Hello everyone. I'm facing an issue here, I followed all steps from installing tailwind-bundle to creating '.symfony.local.yaml', with the right content inside, and when the server starts, it shows
[ok] Started worker "tailwind", but when I add 'text-2xl' class, it doesn't reflect on the browser. I reviewed app.css on page source, it actually has all content from /var/tailwind/app.built.css file, but failed to have 'text-2xl' class in it. I'm using Windows OS.Hey Lemin,
How does your
.symfony.local.yamlconfig file look like? As an alternative solution, you can comment out that Tailwind command in.symfony.local.yamland instead run it in a separate console tab to make sure it works this way. Also, what OS are you on?Cheers!
Hi Victor, I tried to run the command in a separate Windows terminal tab at first, but as I add classes it doesn't seem to track class changes in twigs templates, and nothing takes effect on the browser . I'm using Windows 10.
Hey Lemin,
Hm, probably a known issue, if you add that class in a CSS file that you include in the main CSS file, IIRC files including may not work well. Could you try to add that CSS class directly in the main CSS file which is app.css I suppose? Will it work for you?
Cheers!
Hi Victor. I can now see it seems to work for all templates except the 'homepage.html.twig' which is being rendered by Main controller:: homepage action.
Hey Lemin,
Hm, make sure you don't override any stylesheet blocks in your homepage.hrml.twig. In theory, if it works in other templates but doesn't in one - then most probably you either have some inconsistency in your code for that page, worth double-checking... or it might be a browser cache problem, try to open Chrome's dev toolbar and do a hard reload of the page, in most cases it should help.
Cheers!
Finally solved. The error in render() rendering
homepage.thml.twiginstead ofhomepage.html.twig.Thank Victor
Hey Lemin,
Great, glad to hear you nailed it :)
Cheers!
i got an error
Hey @Himanshu ,
Probably a temporary network issue in your region? Does the GitHub website work well for you? Could you open that https://github.com/tailwindlabs/tailwindcss/releases/download/v3.4.17/tailwindcss-windows-x64.exe link in your browser? Does it download the file for you? If it works - could you try again?
Cheers!
Working successfully :)
Hey Himanshu,
Awesome, thanks for confirming it worked eventually :)
Cheers!
Anyone uses VS code ?
I'm getting: "spawn /usr/bin/php ENOENT" code error on it.
on "symfony server:start " i'm getting:
Workers PID 12968: C:\xampp\php\php-cgi.exe -b 49773 -d error_log=C:\Users\wuwu5.symfony5\log\cd0ebfaea3f058bd6bb595d3f05f2e1a2651620f.log
checked the log files but it was empty. tried changing php path several times but it didn't work.
Hey John,
I personally don't use VS code so can't help you much on it. I see you're on Windows OS and sue XAMPP, could you make sure the XAMPP is started and working? Maybe try to reload it.
Also, the error "spawn /usr/bin/php ENOENT" usually indicates that the system is unable to find PHP at the specified path (/usr/bin/php), which could be due to a misconfiguration in your environment. Please, make sure the path you're using to the PHP is correct. There are a few commands that may help you to debug it:
Probably you need to refresh your PHP versions first, and then make sure the list command shown the correct path to the correct PHP.
Also, check your
.vscode/settings.jsonto make sure there are no path to the invalid PHP binary, fix the path if needed. IIRC it should be something likephp.executablePathconfig parameter there.I hope that helps!
Cheers!
Could you please share how you made the tailwind css intellisense and autocomplete work with Phpstorm?
Tailwind plugin installed - Yes
All instructions per course followed - Yes
Tailwind is initialized. Command to watch and rebuild works fine. Just the IDE intellisense and autocomplete isn't working. I suspect this has to do with us not using node modules for tailwind and just using the tailwind-cli. Not an expert on this. Any guidance to fix this is much appreciated. Thanks in advance.
Hey Jake!
Your totally right: it's because the
node_modulesisn't there, which is really annoying! I think that I'm getting some autocompletion in PhpStorm simply because it recognizes me using Tailwind classes (and maybe it sees mytailwind.config.js. But I don't think I've done anything extra! Here's some info on this topic: https://github.com/SymfonyCasts/tailwind-bundle/issues/28 including a link to the issue for PhpStorm where you can upvote!You can also install Tailwind via npm just to get the autocompletion. Annoying, but functional.
Cheers!
Just a follow up question. I am planning to use daisyui components. With the asset mapper, the only way I found sane is to use a custom standalone tailwind cli with prepackaged daisyui. Is there a way to take advantage of this binary when installing tailwindcss using the symfonycasts bundle? For now I replaced the binary manually inside folder var/tailwind/3.x.x/
https://github.com/dobicinaitis/tailwind-cli-extra/releases
Thanks in advance 🙏🙏🙏🙏🙏🙏🙏🙏
Hey @Jake!
I'm pretty sure this is possible! You'd need to manually download that binary and have the tailwind bundle point to it (instead of its default). See https://symfony.com/bundles/TailwindBundle/current/index.html#using-a-different-binary for how to configure that.
I'm curious to see if that would work so let us know!
Works like a charm! thank you.
Thanks Ryan! I did just that. Annoying but it works! But frustrating when it didn't work.
npm install -D tailwindcss
Hi,
Does it has a LiveReloader ? - edit twig template and see changes immediately in browser
Thank you.
Hey Ruslan,
TailwindCSS itself does not include a built-in live reloading feature, but I think you can easily set up live reloading using development tools commonly used with TailwindCSS. Live reloading is typically handled by tools like Webpack or Vite, though I have never done it before, so not sure about the exact code.
I hope that helps!
Cheers!
Hi there,
I've spoted an issue with tailwind intelisense in PhpStorm on asset mapper that there is no class autocomplete (text-2+enter = text-2xl). I've tested it with bootstrap, and webpack encore on tailwind and it work perfectly fine. I also did so on vscode and it works on base project. Tailwind as is works, i mean classes are applyed, only way to see them is by
symfony console assets:installbut only for currently used class. Do you have idea why?Project made by running
symfony new name --webappand following commands on video.Hey HardWare,
There's a "Tailwind CSS" PhpStorm plugin, I bet if you install that - you will have auto-completion for all Tailwind CSS classes, not only those you've used before in the project :)
Cheers!
"Houston: no signs of life"
Start the conversation!