Skip to content

Instantly share code, notes, and snippets.

@itsmikita
Created September 16, 2023 04:54
Show Gist options
  • Save itsmikita/1599fd23dd74b59304df5aef6d716959 to your computer and use it in GitHub Desktop.
Save itsmikita/1599fd23dd74b59304df5aef6d716959 to your computer and use it in GitHub Desktop.
Hot-reloading PHP with `bun.js` and `Caddy`
localhost
root * public
encode gzip
php_fastcgi 127.0.0.1:9000
file_server {
index index.php index.html
}
@static {
file
path *.ico *.css *.js *.gif *.webp *.jpg *.jpeg *.png *.svg *.woff *.woff2
}
header @static Cache-Control max-age=0
import { watch } from "fs";
import { exec } from "child_process";
exec( "bun run browser" );
const watcher = watch(
"./public",
{ recursive: true },
( event, filename ) => {
console.log( `bun: Detected ${event} in ${filename}` );
exec( "bun run browser" );
}
);
{
"scripts": {
"dev": "bun run server & bun run index.ts",
"server": "caddy run",
"browser": "open -a Safari https://localhost -g"
},
"devDependencies": {
"@types/node": "^20.6.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment