maizzle build [environment], you might ask yourself:
- Should CSS be inlined?
- Should my HTML be minified?
- Do I need to make some data available to the templates?
Default environments
Maizzle comes with two config files, each enabling its own build command:| File | Command |
|---|---|
config.js | maizzle buildmaizzle serve |
config.production.js | maizzle build productionmaizzle serve production |
config.production.js and maizzle build production - the keyword in the config file name enables its own build command.
Remember, the
maizzle executable will only be available if you installed the CLI tool globally. Otherwise, use the NPM scripts provided by the Starter in package.json.Config file naming
You may use themaizzle.config.js configuration file naming pattern if you prefer:
| File | Command |
|---|---|
maizzle.config.js | maizzle buildmaizzle serve |
maizzle.config.production.js | maizzle build productionmaizzle serve production |
CJS config
If you need to use CommonJS withmodule.exports and require() in your Maizzle config file, you’ll need to change the file extension to .cjs:
| ESM | CJS |
|---|---|
config.js | config.cjs |
config.production.js | config.production.cjs |
maizzle.config.js | maizzle.config.cjs |
maizzle.config.production.js | maizzle.config.production.cjs |
Data merging
Any new Environment configuration file that you create will be merged on top of the baseconfig.js when you run the build command for that particular Environment.
With the example above, when running the maizzle build production command, config.production.js will be merged on top of the base config.js: if the same key is present in both files, the value from config.production.js will be used.
When creating a new Environment config file you only need to specify the config values that will be different from those (or don’t exist) in
config.js.Environment builds
To build your emails for a specific Environment, pass its name as an argument to themaizzle build command:
config.production.js is configured to output production-ready emails in a build_production folder at the root of the project.
Custom environments
You may create as many Environments as you need, and name them as you like. For example, you might create a config file namedconfig.shopify.js that you would use to build only the templates from the emails/shopify folder:
config.shopify.js
Config variables
Maizzle exposes apage object that you can access through expressions in your HTML.
This object contains the computed Template config, which is based on config.[env].js merged with Front Matter variables from the Template currently being processed.
This makes it possible to define variables in config.js:
config.js
emails/example.html
Current environment
The current Environment name is globally available under thepage.env variable.
You can output content in your emails based on the Environment that you’re building for:
emails/example.html
You may also use the
<env:production> tag, see the docs.Top-level variables
You may define ‘local’ variables that can be accessed outside of thepage object:
config.js
page:
emails/example.html
Top-level await
You may use top-levelawait in your config.js to fetch data from an API:
config.js
Environment attribute values
Sometimes you may need to define different values for attributes based on the Environment you’re building for. While you could use long, verbose ternaries in expressions to do so:emails/example.html
emails/example.html
href-production attribute will be used for the href attribute when doing npm run build or maizzle build production.
The href-production attribute itself will then be removed from the output.