Tailwind CSS binary wrapper for Forge Kernel. Provides a lightweight alternative to npm-based Tailwind setup with automatic binary download, platform support, and HMR capabilities.
ForgeTailwind is a CLI-only module that provides a PHP wrapper around the Tailwind CSS standalone binary. It allows you to use Tailwind CSS without npm, node_modules, or Node.js dependencies, making it a lightweight alternative for those who prefer to avoid the npm ecosystem.
Optional Alternative: ForgeTailwind is an optional alternative to the standard npm-based Tailwind setup. You can still use Tailwind CSS the normal way with npm and Node.js if you prefer. This module is provided as a personal preference for those who want to avoid npm/node_modules baggage.
CLI-Only Module: ForgeTailwind is a CLI-only module (isCli: true, order: 99), providing Tailwind CSS build capabilities without any runtime dependencies. It's a generic module that can be installed as needed.
ForgeTailwind uses a standalone binary approach, wrapping the official Tailwind CSS standalone binary in PHP CLI commands. This eliminates the need for npm, node_modules, or Node.js while still providing full Tailwind CSS functionality.
Instead of using npm to install Tailwind CSS, ForgeTailwind uses the official Tailwind CSS standalone binary:
storage/bin/PHP CLI commands wrap the Tailwind binary:
The Tailwind CSS binary reads tailwind.config.js just like the npm version:
tailwind.config.js are fully supported
Example tailwind.config.js:
module.exports = {
content: [
'/app/resources/views/**/*.php',
'/modules/**/src/resources/views/**/*.php',
],
theme: {
extend: {},
},
plugins: [
require("@tailwindcss/forms"),
require("@tailwindcss/typography")
],
};
Note: The standalone binary reads and processes tailwind.config.js exactly like the npm version. All plugins, theme customizations, and configuration options work identically.
JavaScript-based Hot Module Replacement:
ForgeTailwind can be installed via ForgePackageManager. It's a CLI-only module with no runtime dependencies.
php forge.php module:package-install --module=forge-tailwind
ForgeTailwind requires:
The Tailwind CSS binary is automatically downloaded on first use. No manual setup is required.
ForgeTailwind was created as a personal preference to avoid npm and node_modules baggage. It's an optional alternative that provides the same Tailwind CSS functionality without requiring Node.js or npm.
This module was created to avoid:
ForgeTailwind provides:
Important points:
Note: This module is provided as a personal preference. Users are free to use Tailwind CSS the normal way with npm and Node.js. ForgeTailwind is just an alternative option for those who want to avoid npm dependencies.
ForgeTailwind provides two CLI commands for building and watching Tailwind CSS.
Builds Tailwind CSS from source files:
php forge.php tailwind:build [--input=CSS_PATH] [--output=CSS_PATH]
--input: Input CSS file path (default: app/resources/assets/css/tailwind.css)--output: Output CSS file path (default: public/assets/css/app.css)# Build with default paths
php forge.php tailwind:build
# Build with custom paths
php forge.php tailwind:build --input=app/resources/css/tailwind.css --output=public/assets/css/app.css
Watches for file changes and automatically rebuilds Tailwind CSS:
php forge.php tailwind:watch [--input=CSS_PATH] [--output=CSS_PATH] [--platform=PLATFORM]
--input: Input CSS file path (default: app/resources/assets/css/tailwind.css)--output: Output CSS file path (default: public/assets/css/app.css)--platform: Tailwind binary platform (default: macos-arm64)macos-arm64 (default)macos-x64windows-x64linux-arm64linux-arm64-musllinux-x64linux-x64-musl# Watch with default settings
php forge.php tailwind:watch
# Watch with custom paths
php forge.php tailwind:watch --input=app/resources/css/tailwind.css --output=public/assets/css/app.css
# Watch with specific platform
php forge.php tailwind:watch --platform=linux-x64
Note: The watch command runs continuously until stopped (Ctrl-C). It automatically rebuilds Tailwind CSS whenever source files change.
ForgeTailwind automatically manages the Tailwind CSS binary, downloading it from GitHub releases when needed.
The binary is automatically downloaded on first use:
storage/bin/Binaries are stored in:
storage/bin/tailwindcss # Unix systems
storage/bin/tailwindcss.exe # Windows
Binaries are downloaded from official Tailwind CSS GitHub releases:
// Example download URL
https://github.com/tailwindlabs/tailwindcss/releases/latest/download/tailwindcss-macos-arm64
The binary is cached after first download:
On Unix systems, the binary is automatically made executable:
exec("chmod +x " . escapeshellarg($tempBin), $out, $ret);
ForgeTailwind supports multiple platforms with platform-specific binaries.
| Platform | Binary Name |
|---|---|
| macOS ARM64 | tailwindcss-macos-arm64 |
| macOS x64 | tailwindcss-macos-x64 |
| Windows x64 | tailwindcss-windows-x64.exe |
| Linux ARM64 | tailwindcss-linux-arm64 |
| Linux ARM64 (musl) | tailwindcss-linux-arm64-musl |
| Linux x64 | tailwindcss-linux-x64 |
| Linux x64 (musl) | tailwindcss-linux-x64-musl |
The platform is selected via the --platform argument in the watch command:
php forge.php tailwind:watch --platform=linux-x64
The default platform is macos-arm64. For the build command, it automatically detects the platform based on the system.
ForgeTailwind includes JavaScript-based Hot Module Replacement for automatic CSS reloading during development.
Hot Module Replacement automatically reloads CSS when Tailwind files are rebuilt, without requiring a full page refresh. This improves the development workflow by preserving form state and scroll position.
HMR is enabled via the APP_HMR environment variable:
# .env
APP_HMR=true
Use the forgetailwind() helper function in your views:
<?php echo forgetailwind(); ?>
This will output the HMR script tag if HMR is enabled and conditions are met.
HMR script is only included when:
APP_HMR is trueproduction or staginglocalhost or 127.0.0.1The HMR JavaScript:
Security: HMR only works on localhost/127.0.0.1 to prevent potential security issues in production environments.
ForgeTailwind provides a helper function for HMR integration.
Returns the HMR script tag if HMR is enabled and conditions are met:
function forgetailwind(): string
{
$isHmrEnabled = env("APP_HMR", false);
$env = env("APP_ENV");
$host = request_host();
if (!$isHmrEnabled) {
return "";
}
if (in_array($env, ["production", "staging"], true)) {
return "";
}
if (
!str_starts_with($host, "localhost") &&
!str_starts_with($host, "127.0.0.1")
) {
return "";
}
return '<script defer src="/assets/modules/forge-tailwind/js/forge-tailwind-hmr.js"></script>';
}
<!DOCTYPE html>
<html>
<head>
<title>My Page</title>
<link rel="stylesheet" href="/assets/css/app.css">
<?php echo forgetailwind(); ?>
</head>
<body>
<!-- Your content -->
</body>
</html>
Returns:
ForgeTailwind uses the standard tailwind.config.js file, which is read by the Tailwind binary just like with npm.
Create a tailwind.config.js file in your project root:
module.exports = {
content: [
'/app/resources/views/**/*.php',
'/app/resources/assets/**/*.js',
'/modules/**/src/resources/views/**/*.php',
],
theme: {
extend: {},
},
plugins: [
require("@tailwindcss/forms"),
require("@tailwindcss/typography")
],
};
Plugins are fully supported. The binary reads and processes plugins from tailwind.config.js:
require() to work)
Note: While ForgeTailwind avoids npm for the Tailwind binary itself, you may still need npm to install plugin packages if you use plugins. The binary reads the config file and processes plugins, but the plugin packages themselves need to be available via require().
Define which files Tailwind should scan for classes:
content: [
'/app/resources/views/**/*.php',
'/app/resources/assets/**/*.js',
'/modules/**/src/resources/views/**/*.php',
]
Customize the Tailwind theme just like with npm:
theme: {
extend: {
colors: {
'brand': '#1da1f2',
},
},
}
ForgeTailwind uses default file paths that can be customized via command arguments.
app/resources/assets/css/tailwind.css
This is your source Tailwind CSS file with @tailwind directives.
public/assets/css/app.css
This is the compiled CSS file that should be included in your HTML.
You can customize both paths using command arguments:
php forge.php tailwind:build \
--input=app/resources/css/custom.css \
--output=public/css/custom.css
/* app/resources/assets/css/tailwind.css */
@tailwind base;
@tailwind components;
@tailwind utilities;
/* Your custom CSS here */
# Build Tailwind CSS with default paths
php forge.php tailwind:build
php forge.php tailwind:build \
--input=app/resources/css/tailwind.css \
--output=public/assets/css/app.css
# Watch for changes and rebuild automatically
php forge.php tailwind:watch
# Watch with custom paths
php forge.php tailwind:watch \
--input=app/resources/css/tailwind.css \
--output=public/assets/css/app.css
# Watch on Linux
php forge.php tailwind:watch --platform=linux-x64
# Watch on Windows
php forge.php tailwind:watch --platform=windows-x64
Enable HMR in your .env:
APP_HMR=true
APP_ENV=local
Include HMR script in your layout:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="/assets/css/app.css">
<?php echo forgetailwind(); ?>
</head>
<body>
<!-- Your content -->
</body>
</html>
php forge.php tailwind:watchAPP_HMR=true in .envForgeTailwind and npm-based Tailwind setup each have their advantages. Choose the approach that best fits your needs.
| Feature | ForgeTailwind | npm-based |
|---|---|---|
| Dependencies | Single binary, no npm | npm, Node.js, node_modules |
| Setup | Automatic binary download | npm install, package.json |
| File Size | Small (single binary) | Large (node_modules) |
| Tailwind Plugins | Full support (reads tailwind.config.js) | Full plugin ecosystem |
| Configuration | Full (tailwind.config.js, same as npm) | Full (tailwind.config.js) |
| HMR | Built-in JavaScript HMR | Vite/Webpack HMR |
| Use Case | Lightweight, simple projects | Full Tailwind ecosystem |
Recommendation: For most projects, the standard npm-based Tailwind setup is recommended. ForgeTailwind is best suited for those who specifically want to avoid npm dependencies or prefer a lightweight alternative.
tailwind:watch during developmenttailwind:build for productionstorage/bin/forgetailwind() helper in layoutsapp/resources/assets/css/public/assets/css/.gitignore if desired