Skip to content

How to Auto-Reload with Baseprinter

This guide shows how to automatically reload previews of Baseprint document snapshots in your web browser when new preview files are generated by Baseprinter.

If you auto-reload previews, you'll likely also want to auto-rerun Baseprinter upon saving your source files.

Prerequisites

You will need either:

OR

Alternatives

This guide uses live-server, but there are many alternatives with similar functionality.

How it works

Run live-server in a separate terminal window, apart from where you run baseprinter and your text editor. live-server watches your Baseprinter preview output directory. Upon any changes to the Baseprint preview generated by Baseprinter, your web browser will automatically reload the preview webpage.

Press CTRL-C to stop live-server.

Run live-server locally

Run live-server with the path to your Baseprinter preview output directory. For instance, if you run baseprinter doc.md --outdir=preview, then run

live-server --no-css-inject preview

Note

Using the --no-css-inject option prevents certain issues with auto-reloading preview HTML files generated by Baseprinter.

After running live-server, you can navigate to http://localhost:8080 to view an HTML preview of the baseprint that reloads automatically.

Running in a container

If you are running Baseprinter in a container, the Baseprinter container image includes live-server. It can be used by setting up a shell function:

live-server() {
  podman run --rm -v=.:/mnt -w=/mnt -p=8080:8080 -it --init \
    registry.gitlab.com/perm.pub/dock/baseprinter live-server "$@"
}

After defining the live-server shell function, you can run live-server as if it were installed locally.

Warning

When running live-server inside a container, be aware that it will not have access to any paths outside the current working directory.