fix(render): make prettier an optional peer dependency

Closed
MA
5mo ago
+97-37

Closes #3608.

prettier was a hard dependency of @react-email/render but is only used on the pretty: true path, which is off by default. This moves it to an optional peer dependency and lazily loads it with a dynamic import, so it no longer ships to consumers who never prettify.

Following @y-nk's outline on the issue (optional dep + dynamic import). One open call: when pretty: true is used without prettier installed, this returns the unformatted HTML and warns once (rather than throwing, since editor/ui call pretty() directly). I can make it a hard throw instead if that's preferred.


Summary by cubic

Make prettier optional in @react-email/render and load it only when pretty: true is used. This reduces install and bundle size for consumers who don’t prettify, with identical output when prettier is present.

  • Dependencies
    • Moved prettier from dependencies to an optional peerDependency and kept it in devDependencies for this repo.
    • Dynamically import prettier/standalone and prettier/plugins/html only when pretty: true is requested.
    • If pretty: true is used without prettier installed, return unformatted HTML and log a one-time warning.
    • Formatting behavior is unchanged when prettier is installed (custom HTML printer tweaks are preserved).