spectate / laravel-react-email
Build Laravel mailables with react-email.
Fund package maintenance!
Spectate
Requires
- php: ^8.2
- illuminate/contracts: ^10.0||^11.0
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- larastan/larastan: ^2.9
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.1.1||^7.10.0
- orchestra/testbench: ^9.0.0||^8.22.0
- pestphp/pest: ^2.34
- pestphp/pest-plugin-arch: ^2.7
- pestphp/pest-plugin-laravel: ^2.3
- phpstan/extension-installer: ^1.3
- phpstan/phpstan-deprecation-rules: ^1.1
- phpstan/phpstan-phpunit: ^1.3
- spatie/laravel-ray: ^1.35
README
Build Laravel mailables with react.email.
Installation
You can install the package via composer:
composer require spectate/laravel-react-email
Next up, install the required NPM packages:
npm i -D typescript react react-email @react-email/components @react-email/render @types/react @types/node
You can publish the config file with:
php artisan vendor:publish --tag="react-email-config"
Optional: Build templates on composer install
If you run composer install
during deployments, this way you will automatically regenerate the React Email templates on each deploy.
To enable this, add the following to your composer.json
file:
{ "post-install-cmd": [ "@php artisan react-email:build" ] }
Usage
Create your first React Email template:
php artisan make:react-email MyFirstEmail
Optional: run the React Email dev server
You can run the React Email dev server to preview your templates:
php artisan react-email:dev
This will start the dev server and watch for changes in your templates.
Next up, edit the files in resources/views/react-emails
and see the changes in your browser.
Using variables
To support variables in the compiled Blade templates, you can use the following syntax in your React Email templates:
export default function MyEmail() { return ( <Html> Hello, $$name$$! </Html> ); }
This will be compiled to the following Blade template:
Hello, {{ $name }}!
Hot reloading
By default, on local development environments, the React Email templates are rendered on-the-fly for every send. This can be disabled by setting the REACT_EMAIL_HOT_RELOAD
environment variable to false
.
Building templates
You can build the React Email templates to HTML using the react-email:build
command:
php artisan react-email:build
This will build all the templates and output them to resources/views/vendor/react-email
.
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.