Created
September 16, 2023 04:54
-
-
Save itsmikita/1599fd23dd74b59304df5aef6d716959 to your computer and use it in GitHub Desktop.
Hot-reloading PHP with `bun.js` and `Caddy`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" ); | |
} | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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