@ email-lint/ react- 电子邮件
林特 反应电子邮件 用于客户兼容的组件。 将您的组件渲染到 HTML 并对照 邮件 使用数据 @ email-lint/ core (韩语)。 。 。 .
import { lintComponent } from '@email-lint/react-email';
import { Welcome } from './emails/welcome';
const result = await lintComponent(<Welcome name="Jane" />);
console.log(result.success); // true
console.log(result.errorCount); // 0
console.log(result.diagnostics); // LintDiagnostic[]
安装
npm install @email-lint/react-email
同伴依赖性 : react 财务报告和审定财务报表 @react-email/render。 。 。 .
API 密码
lintComponent(element, config?)
通过 HTML 将反应元素渲染到 HTML @react-email/render,然后将其涂入 email-lint。 。 。 .
默认情况下启用了框架感知过滤 —— React Email 内部导致的诊断(审查文本块,预装图像标记,强制) target="_blank")自动被压制. 过 framework: undefined 选择退出.
// Lint against specific clients
const result = await lintComponent(<Welcome />, { preset: 'gmail' });
// Disable framework filtering
const result = await lintComponent(<Welcome />, { framework: undefined });
// Keep suppressed diagnostics visible
const result = await lintComponent(<Welcome />, { showIgnored: true });
返回同样的 LintResult 类型为 @email-lint/core 看到了吗 @ email-lint/ 核心文档 用于完整类型参考.
用于测试
import { describe, it, expect } from 'vitest';
import { lintComponent } from '@email-lint/react-email';
import { Welcome } from './emails/welcome';
describe('email compatibility', () => {
it('Welcome has no errors', async () => {
const result = await lintComponent(<Welcome name="Jane" />);
expect(result.errorCount).toBe(0);
});
it('Welcome passes Gmail checks', async () => {
const result = await lintComponent(<Welcome name="Jane" />, { preset: 'gmail' });
expect(result.success).toBe(true);
});
});
许可证
麻省理工学院