Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion packages/react-email/src/commands/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ import { setupHotreloading, startDevServer } from '../utils/index.js';
interface Args {
dir: string;
port: string;
resendApiKey?: string;
}

export const dev = async ({ dir: emailsDirRelativePath, port }: Args) => {
export const dev = async ({
dir: emailsDirRelativePath,
port,
resendApiKey,
}: Args) => {
try {
if (!fs.existsSync(emailsDirRelativePath)) {
console.error(`Missing ${emailsDirRelativePath} folder`);
Expand All @@ -17,6 +22,7 @@ export const dev = async ({ dir: emailsDirRelativePath, port }: Args) => {
emailsDirRelativePath,
emailsDirRelativePath, // defaults to ./emails/static for the static files that are served to the preview
Number.parseInt(port, 10),
resendApiKey,
);

await setupHotreloading(devServer, emailsDirRelativePath);
Expand Down
4 changes: 4 additions & 0 deletions packages/react-email/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ if (!hasRequiredFlags) {
'./emails',
)
.option('-p --port <port>', 'Port to run dev server on', '3000')
.option(
'--resend-api-key <key>',
'Resend API key for the preview app (overrides stored config)',
)
.action(dev);

program
Expand Down
4 changes: 3 additions & 1 deletion packages/react-email/src/utils/preview/start-dev-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const startDevServer = async (
emailsDirRelativePath: string,
staticBaseDirRelativePath: string,
port: number,
resendApiKey?: string,
): Promise<http.Server> => {
const [majorNodeVersion] = process.versions.node.split('.');
if (majorNodeVersion && Number.parseInt(majorNodeVersion, 10) < 20) {
Expand Down Expand Up @@ -97,6 +98,7 @@ export const startDevServer = async (
emailsDirRelativePath,
staticBaseDirRelativePath,
nextPortToTry,
resendApiKey,
);
}

Expand Down Expand Up @@ -132,7 +134,7 @@ export const startDevServer = async (
path.normalize(emailsDirRelativePath),
previewServerLocation,
process.cwd(),
conf.get('resendApiKey'),
resendApiKey ?? conf.get('resendApiKey'),
),
};

Expand Down
Loading