arnolem / tailwindphp

TailwindPHP - use Tailwind CSS in your PHP projects (without npm)
https://wixiweb.fr
MIT License
7 stars 3 forks source link

haw question #2

Open vahidalvandi opened 4 months ago

vahidalvandi commented 4 months ago

I have a question, thank you for your help. Suppose I have an html page on the Apache host without node, which I want to use tailwind and after I enter the code once, it will compile it and the css will be made according to it.

arnolem commented 4 months ago

Hello,

TailwindPHP is in charge of compilation but is not in charge of caching. You can send the result of TailwindPHP in a statically delivered file on the second request.

One trick is to use a file path that matches the dynamic route exactly (Eg /style.css).

    #[Route('/style-{version}.css', name : 'css')]
    public function css(string $version):Response
    {
        $css = TailwindPhp::build();

        if ($this->enableCache) {
            file_put_contents('./public/style-' . $version . '.css', $css);
        }

        return new Response($css, Response::HTTP_OK, ['Content-Type' => 'text/css']);
    }

This is just an example but you need to adapt it to your case.