Let's touch down how Tailwind CSS works on WordPress efficiently and how Laravel Mix has a big impact on watching the PHP and the CSS files inside.
Let's jump on it!
So first, we need to install the following tools that we need.
We must use version 3.4.17
since it's the compatible version to be used for now.
Install Tailwind CSS by running the npm command:
npm install -D tailwindcss@3
tailwind.config.js
/** @type {import('tailwindcss').Config} */
module.exports = {
content: [
"./src/**/*.{js,jsx,ts,tsx}",
"./*.php",
"./templates/**/*.php",
"./inc/**/*.php",
"./assets/**/*.js"
],
theme: {
extend: {},
},
plugins: [],
};
src/main.css
)@tailwind base;
@tailwind components;
@tailwind utilities;
npx tailwindcss -i ./src/main.css -o ./src/main.css --watch
npm init -y
npm install laravel-mix --save-dev
npm install -g browser-sync
webpack.mix.js
)let mix = require('laravel-mix');
mix.postCss("src/css/main.css", "dist/main.css", [
require("tailwindcss"),
])
.browserSync({
proxy: "http://wordpress-site.test", // Change this to your local WP URL
files: [
"**/*.php", // Watch all PHP files
"dist/main.css" // Watch the compiled Tailwind CSS
]
});
package.json
ScriptsAdd the following scripts to the package.json
file:
"scripts": {
"build": "mix",
"watch": "mix watch"
}
npm run build
npm run watch
By integrating Tailwind CSS and Laravel Mix into your WordPress theme development workflow, you can significantly improve efficiency and maintainability. Tailwind CSS provides a powerful utility-based approach to styling, while Laravel Mix simplifies asset management and live reloading with BrowserSync. This setup ensures that your styles are always up to date and that changes in your PHP files are instantly reflected in your browser.
With this approach, you can focus more on building great designs and functionality without worrying about manual CSS updates. Happy coding! ๐