Skip to content

Commit 24a9f54

Browse files
committed
feat(docs): IMproved email dev section on the static files
1 parent edd78ce commit 24a9f54

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

apps/docs/cli.mdx

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ This does adjust to your `--dir` option, so if your `emails` directory was insid
2222
of `./src/emails`, you would place your static files inside of `./src/emails/static`.
2323

2424
These static files are directly served from our preview server by looking into the
25-
requests made into that end with `/static` and serving the files at that point,
25+
requests made into that end with `/static` (i.e. `http://localhost:3000/static/...`) and serving the files at that point,
2626
this also allows for you to have images inside of your emails like so:
2727

2828
```jsx
@@ -35,6 +35,31 @@ export default Email(props) {
3535
}
3636
```
3737

38+
<Info>
39+
This does not mean your images are hosted for you to send the emails,
40+
if you do send your email here and you are using a image or similar inside of `emails/static`
41+
they will not load properly on the email.
42+
</Info>
43+
44+
Of curse, more often than not you will need to host your images on a CDN, so we recommend
45+
you change the `src` to the CDN's base url based on the environment like:
46+
47+
```jsx
48+
const baseURL = process.env.NODE_ENV === 'production'
49+
? 'https://cdn.com'
50+
: ''
51+
52+
export default Email(props) {
53+
return (
54+
<div>
55+
<img src={`${baseURL}/static/email-logo.png`} />
56+
</div>
57+
)
58+
}
59+
```
60+
61+
You can refer to our [demo emails source code](https://demo.react.email/preview/vercel-invite-user.tsx?view=source) for an example of how we do this.
62+
3863
### How to make the preview server ignore directories
3964

4065
Once the preview server has started and is now open on `localhost`, the preview server

0 commit comments

Comments
 (0)