Skip to content
This repository has been archived by the owner on Apr 19, 2024. It is now read-only.

Preparing for deployment to Ontario.ca

Kevan Hannah edited this page Apr 27, 2023 · 2 revisions

Building your application

npm run build will generate the application in the dist directory (after removing it to ensure a clean build). This directory can then be deployed to a suitable hosting environment for serving static content.

Environment-dependent variables

For values that need to differ between environments, the basic approach described in the Eleventy documentation has been used has been used. This lets you do the following:

  • when building: ELEVENTY_ENV=stage npm run build - sets the build environment to stage or another value
  • in templates: {​​​{​​​ globals.environment }​​​​​​​​​​}​​​​​​​​​​ to access the supplied value of ELEVENTY_ENV (defaults to development if no value supplied)
  • in _data/globals.js: use the env value in module.exports to implement environment-differentiated variables or functions to supply to your templates
    • The userFriendlyEnvString values provides a simple example of how to do this

Site root configuration

Jamstack sites deployed to Ontario.ca will need a configured site root based on their deployment subfolder. The siteRootEnvs object in src/_data/app/app-globals.js can be used for these purposes.

Build output configuration

Eleventy can be configured to build site outputs that are different from the source input by modifying options in the .eleventy.js configuration file, which is made up of a combination of configuration functions and options in two files:

  • .app-eleventy.js (a point for your application's configuration)
  • .core-eleventy.js (core configuration, do not modify)

The default state of the toolkit shows some examples of this approach that aligns with deploying Jamstack sites to Ontario.ca:

  • The addPassthroughCopy statement in .app-eleventy.js copies the root-level assets folder in src to the jamstack-toolkit folder of the built site
  • The assetsPath variable from src/_data/app/app-globals.js is used to reference the build location of the assets folder in the templates

This configuration simplifies deployment to Ontario.ca by requiring only two routes to be configured (one for each language) with an assets directory shared between the two.

Clone this wiki locally