Environments
When developing HTML emails, you might want to use different data and automations in your local and production environments.
For example, you don't need CSS inlining or purging when developing on your machine, but you'll want both enabled for the final, production-ready emails.
Inspired by Jigsaw's approach, Maizzle makes this easy by allowing you to create custom build environments through additional config.[env].js
files.
Creating environments
Think of environments as 'build scenarios':
When I run
maizzle build [environment]
, should X happen? Should CSS be inlined? Should my HTML be minified? Do I need some data to be available for the templates?
For example, let's define a production environment, by creating a new file named config.production.js
, in the project root:
// config.production.js
module.exports = {
build: {
destination: {
path: 'build_production',
},
}
}
Here, we specify that the files we build when running maizzle build production
should be output to a build_production
folder relative to the project root.
Merging
Any new environment you create will be merged on top of the base config.js
when you run the build command for that environment.
So in the case above, you only need to specify the config values that you are changing for the production
environment.
Environment builds
To build your emails for a specific environment, pass the environment name as an argument to the maizzle build
command:
maizzle build production
config.[env].js
is not found, the build will fail.By default, running maizzle build production
will output production-ready emails in a build_production
folder at the root of the project.
This output path is, of course, configurable.
Starter environments
Maizzle comes with two Environment configs:
local
production
Local
The base config.js
is tailored to local development.
CSS purging, inlining, and most other Transformers are disabled, so you can quickly prototype your emails with all of Tailwind's classes at your disposal.
Build command:
maizzle build
This has the fastest build time, since there is almost no post-processing going on.
config.local.js
, if you prefer - Maizzle will pick it up and use it when developing locally.Production
config.production.js
is configured to output production-ready email code, formatted with humans in mind.
CSS purging and inlining are enabled, but code is prettified so that you can share nicely-formatted, more readable code with other people.
Build command:
maizzle build production
Custom environments
You can create as many build environments as you need, and name them as you like.
For example, create a config file named config.shopify.js
, that you would use to build only the templates from the src/clients/shopify
folder.
The build command for it would be:
maizzle build shopify
Template conditional
You can output content in your emails based on the environment you're building for.
The environment name is globally available under the page.env
variable:
<if condition="page.env === 'production'">
This will show only when running `maizzle build production`
</if>