Extending your build process with hooks

Last modified: February 15th, 2024

Working with a specific static site generator?
Customize CloudCannon's documentation to suit your SSG.

Great! We'll show you documentation relevant to .
You can change this any time using the dropdown in the navigation bar.

Bash scripts that run at different stages in the build to extend the functionality of your sites. There are three hooks available: Preinstall, Prebuild, and PostBuild. All three are configured using extensionless script files.

To run a hook script:

  1. Create one of the named files in the .cloudcannon folder at the root of your file structure
  2. Enter the commands you want to run at the specified step

Preinstall#

A script at /.cloudcannon/preinstall which runs after the files are available and before any install scripts.

Preinstall scripts are useful for configuring your install commands before they run.

Prebuild#

A script at /.cloudcannon/prebuild which runs after the install scripts and before any build commands.

Prebuild commands allow you to incorporate your favourite tools for building and pre-processing into CloudCannon. Some ideas for using this feature include:

  • Bundling JavaScript
  • Fetching API data
  • Running build commands outside of your SSG
  • Sending messages to your Slack channel

Here’s an example file that bundles JavaScript files using webpack:

/.cloudcannon/prebuild
copied
#!/bin/bash

npm install webpack
npm install webpack-cli

./node_modules/.bin/webpack path/to/entry.js -o js/output.js

Postbuild#

A script at /.cloudcannon/postbuild which runs after your build is completed successfully before the files are uploaded to CloudCannon servers.

Postbuild scripts are useful for augmenting your built output or running postbuild webhooks.

If your postbuild script adds, removes or updates files used by the editor, your editing experience may be compromised.

Open in a new tab