Hi everyone!
I recently encountered a challenge when I started using Tailwind CSS in a PHP project. I needed to generate an optimized build for production, but the process wasn’t straightforward. Instead of diving into existing solutions, I created a simple script to address this problem. This script generates a output.css file, which you can seamlessly integrate into your PHP project.
The script processes your PHP files, creates corresponding HTML mirrors, and builds a production-ready Tailwind CSS output.css file. This is particularly useful for PHP projects where integrating Tailwind’s build tools directly may be cumbersome.
Ensure you have the following installed on your system:
- Node.js
- npm (Node Package Manager)
-
Get the Script:
- Copy the code or download the
generate_mirror.phpfile from this repository.
- Copy the code or download the
-
Setup:
- Place the
generate_mirror.phpfile in your project directory. - Edit the script to include the PHP files you want to process by adding their paths to the
$phpFilesarray.
- Place the
-
Run the Script:
- Open your terminal.
- Navigate to the directory where the
generate_mirror.phpfile is located. - Execute the script by running:
php generate_mirror.php
-
Wait for Completion:
- The script will create mirror HTML files and then build Tailwind’s
output.css. This process might take a minute or two.
- The script will create mirror HTML files and then build Tailwind’s
-
Retrieve the CSS File:
- Navigate to the
mirror_htmlfolder. - Copy the generated
output.cssfile and include it in your PHP project.
- Navigate to the
This script was written as a quick solution, and there’s always room for improvement. If you encounter any bugs or have suggestions, please create a pull request. Your contributions and feedback are highly valued and will help make this tool even better.
Peace,
Muswalo