Turborepo Setup

Turborepo is a popular monorepo management tool. Mailing works great with Turborepo but there are a few ways to set it up depending on your needs.

Option 1: different email templates per app

This is the simpler setup and is best if you're just using Mailing to send emails from a single app or if each one of your apps has its own templates. You can still share template components across apps via a shared package but each app will have it's own emails directory with templates and previews.

To set this up, go to your app’s directory and install mailing and mailing-core then setup with npx mailing init as usual. Full setup instructions in the Readme should just work in your app's directory.

Example: https://github.com/sofn-xyz/mailing-turborepo-example/tree/email-per-app

Option 2: package with shared emails across apps

This is a more complicated setup intended for cases where you have different apps that should all be able to send the same emails.

  1. Add an internal package called packages/emails. You'll want to install mailing, mailing-core, next, react, and react-dom in here. If you're using typescript, you'll also need to add @types/react and @types/react-dom
  2. Add an packages/emails/index.ts that exports your templates and emails/index.
  3. Refer to this as your packages/emails/package.json entrypoint. Add a dev script to this as well to boot up the preview server when you boot your other apps.
  4. Import this package into apps where you want to use it. For a next app, you'll want to add it to transpilePackages in your next.config.js. Then you can import it into API routes that run on the server (hello world example).

Example: https://github.com/sofn-xyz/mailing-turborepo-example/tree/shared-emails