Back to React Email

Setting up for npm workspaces

apps/docs/getting-started/monorepo-setup/npm.mdx

0.0.152.0 KB
Original Source

1. Create workspace

Create a new folder called transactional inside of where you keep workspace packages (generally ./packages/*).

Include a new package.json and do not forget to add this to the workspaces of your monorepo's package.json.

<Card title="React Email + Turborepo + npm example" icon="arrow-up-right-from-square" href="https://github.com/resend/react-email-turborepo-npm-example"

See the full source code </Card>

2. Install dependencies

Install React Email in the transactional workspace.

sh
npm install react-email @react-email/preview-server -D -E
npm install @react-email/components react react-dom -E

3. Add scripts

Include the following script in your package.json file.

json
{
  // ...
  "scripts": {
    "dev": "email dev"
  }
  // ...
}

4. Write your emails

Create a new folder called emails, create a file inside called email.tsx and add the following example code:

jsx
import { Button, Html, Head, Body } from "@react-email/components";
import * as React from "react";

export default function Email() {
  return (
    <Html>
      <Head />
      <Body>
        <Button
          href="https://example.com"
          style={{ background: "#000", color: "#fff", padding: "12px 20px" }}
        >
          Click me
        </Button>
      </Body>
    </Html>
  );
}

5. Run preview server

Start the email previews development server:

sh
npm run dev

6. See changes live

Visit localhost:3000 and edit the emails/email.tsx file to see the changes.

<Frame> </Frame>

7. Try it yourself

<Card title="React Email + Turborepo + npm example" icon="arrow-up-right-from-square" href="https://github.com/resend/react-email-turborepo-npm-example"

See the full source code </Card>