spectate/laravel-react-email

Build Laravel mailables with react-email.

0.1.4 2024-10-12 16:28 UTC

This package is auto-updated.

Last update: 2024-10-12 16:29:11 UTC


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

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.