Skip to content

Commit 22e7b58

Browse files
committed
Added mjml compilation option to shopware-cli project command
1 parent 368e4bd commit 22e7b58

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

products/cli/project-commands/build.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,60 @@ build:
4545
4646
You can check [here which browsers would be affected](https://browsersl.ist/#q=defaults).
4747
48+
## MJML Email Template Compilation
49+
50+
Starting with Shopware CLI 0.6.26, the `project ci` command can compile MJML email templates during the build process
51+
for projects using the [FroshPlatformTemplateMail](https://github.com/FriendsOfShopware/FroshPlatformTemplateMail) plugin.
52+
[MJML](https://mjml.io) is a markup language designed to reduce the pain of coding responsive emails by providing
53+
semantic components that compile to responsive HTML.
54+
55+
### Prerequisites
56+
57+
This feature is specifically designed for projects using the **FroshPlatformTemplateMail** plugin. The primary purpose of this plugin is to manage email templates as source files in your codebase, rather than storing them in the database. This approach enables:
58+
59+
- **Version control**: Email templates can be tracked in Git alongside your code
60+
- **Deployment consistency**: Templates are deployed with your code, ensuring consistency across environments
61+
- **MJML support**: Optionally write templates in MJML (Mailjet Markup Language) format for responsive emails
62+
- **Build-time compilation**: Since templates are in source files, they can be compiled during the build process
63+
64+
Having email templates in source files is essential for the shopware-cli MJML compilation feature to work, as it processes these files during the build phase.
65+
66+
### Why compile MJML during build?
67+
68+
By default, FroshPlatformTemplateMail compiles MJML templates at runtime when emails are sent. The shopware-cli build-time compilation offers several advantages:
69+
70+
- **Early error detection**: Catch MJML syntax errors during CI/CD instead of when sending emails
71+
- **Better performance**: Eliminate runtime compilation overhead
72+
- **Improved reliability**: Remove potential runtime failures in production
73+
- **Reduced dependencies**: No need for MJML compilation services in production
74+
75+
### Configuration
76+
77+
Enable MJML compilation in your `.shopware-project.yml` file:
78+
79+
```yaml
80+
build:
81+
mjml:
82+
# Enable MJML compilation during build
83+
enabled: true
84+
# Directories to search for MJML templates (defaults to custom/plugins and custom/static-plugins if not specified)
85+
searchPaths:
86+
- custom/plugins
87+
- custom/static-plugins
88+
```
89+
90+
### How it works
91+
92+
When MJML compilation is enabled:
93+
1. The CLI searches for `html.mjml` files in the configured search paths (defaults to `custom/plugins` and `custom/static-plugins`)
94+
2. Each `html.mjml` file is compiled to HTML and saved as `html.twig`
95+
3. The original `html.mjml` files are removed after successful compilation to prevent runtime re-compilation attempts
96+
4. Any compilation errors are reported and cause the build to fail, ensuring broken templates don't reach production
97+
98+
### Requirements
99+
100+
MJML compilation requires the `mjml` package to be installed via NPM in your build environment. The CLI uses local compilation to convert MJML templates to HTML.
101+
48102
## Configuration options
49103

50104
You can configure the build process with a `.shopware-project.yml` file. The following options are available:
@@ -71,6 +125,12 @@ build:
71125
# Allows to force building an extension even when the assets existing. A use-case could be if you used composer patches for a specific extension.
72126
force_extension_build:
73127
- name: 'SomePlugin'
128+
# MJML compilation configuration (see MJML section above for details)
129+
mjml:
130+
enabled: false
131+
searchPaths:
132+
- custom/plugins
133+
- custom/static-plugins
74134
```
75135

76136
## Supporting bundles

0 commit comments

Comments
 (0)