statamic / ssg

The official Statamic Static Site Generator
232 stars 24 forks source link

Add an `ssg:serve` command for local testing #121

Closed jacksleight closed 1 year ago

jacksleight commented 1 year ago

When developing locally it can be useful to test out the SSG and its generated output, but you can't just open the site up in a browser as all the links and asset URLs are absolute and have to point to a real host.

This PR adds an ssg:serve command that launches the PHP dev server in the SSG destination folder.

The way I'm using this is by creating a .env.serve file:

APP_NAME="Example"
APP_ENV=production
APP_DEBUG=false
APP_URL=http://127.0.0.1:8000
...

Then running:

php please ssg:generate --env=serve
php please ssg:serve

The command itself is just a stripped down and tweaked version of Laravel's serve command.

what-the-diff[bot] commented 1 year ago
jasonvarga commented 1 year ago

Rad! I had wanted to do this for a while. I actually find myself running ssg:serve thinking it already existed.

Shame we need to reinvent the command. It would be neat if you artisan serve could be given a directory. Oh well.

jacksleight commented 1 year ago

Yeah that was my first thought too! I did consider extending the Laravel command and just overriding the startProcess method, but that felt a bit untidy. And the Laravel command is doing a bunch of stuff that's not really needed here.

jacksleight commented 1 year ago

Don't suppose this could be released?

jasonvarga commented 1 year ago

Whoops, sorry 😬 Tagged now.