如何使用vite将tailwindcss样式应用于Laravel9中的电子邮件

我无法在邮件刀片中制作工作风格。

我无法在邮件刀片中制作工作风格。

最终目标是为邮件布局。到现在为止,为了测试 puposes,我有:

发送邮件的控制器

邮件组件

可邮寄的类

电子邮件的布局,作为 guest.blade.php jetstream 文件的副本

一个特定的电子邮件刀片文件,即要在 previus 布局中添加的内容,是 welcome.blade.php jetstream 文件的副本

app\ Http\ Controllers\ TestController.php

<?php
namespace App\Http\Controllers;
use App\Mail\TestingMail;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Mail;
cl TestController extends Controller
{
    public function __invoke(Request $request)
    {
        $result = Mail::to($request->user())
                ->send(new TestingMail());
        return view('welcome');
     }
}

app\ View\ Components\ MailLayout.php

<?php
namespace App\View\Components;
use Illuminate\View\Component;
cl MailLayout extends Component
{
    /**
     * Create a new component instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }
    /**
     * Get the view / contents that represent the component.
     *
     * @return \Illuminate\Contracts\View\View|\Closure|string
     */
    public function render()
    {
        return view('layouts.mail');
    }
}

app\ Mail\ TestingMail.php

<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
cl TestingMail extends Mailable
{
    use Queueable, SerializesModels;
    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }
    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this->view('mails.general');
    }
}

资源\ 视图\ 布局\ mail.blade.php

<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
    <head>
        <meta cht="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="csrf-token" content="{{ csrf_token() }}">
        <title>{{ config('app.name', 'Laravel') }}</title>
        <!-- Fonts -->
        <link rel="stylesheet" href="https://fonts.bunny.net/css2?family=Nunito:wght@400;600;700&display=swap">
        <!-- Scripts -->
        @vite(['resources/css/app.scss', 'resources/js/app.js'])
    </head>
    <body>
        <div cl="font-sans text-gray-900 antialiased">
            {{ $slot }}
        </div>
    </body>
</html>

resources\ views\ mails\ general.blade.php

<x-mail-layout>
    <x-slot name="header">
        <h2 cl="font-semibold text-xl text-gray-800 leading-tight">
            {{ __('Dashboard') }}
        </h2>
    </x-slot>
    <div cl="py-12">
        <div cl="max-w-7xl mx-auto sm:px-6 lg:px-8">
            <div cl="bg-white overflow-hidden shadow-xl sm:rounded-lg">
                <x-jet-welcome />
            </div>
        </div>
    </div>
</x-mail-layout>

我收到没有样式的邮件。我发现的唯一帮助是这个链接https://ralphjsmit.com/tailwind-css-multiple-configurations-laravel-mix,但这是为 laravel mix 写的,我不知道将这个 webpack.mix.js 迁移到 vite。

任何帮助或方向将 apreciated,谢谢。

编辑我最终使它工作,结合 @ Jaap 的答案和其他包:https://github.com/fedeisas/laravel-mail-css-inliner

https://github.com/motomedialab/laravel-vite-helper

vite helper 并不理想,因为它在 npm run dev 运行时不起作用,但对我来说已经足够了。

1

对于电子邮件,您希望内联样式。我不认为这是 Vite,Tailwind 或 Blade 开箱即用的功能。

但是,有一个包似乎可以解决您的问题:https://github.com/fedeisas/laravel-mail-css-inliner

以前从未尝试过,但似乎很活跃。但是,自动内联的做法对于电子邮件来说很普遍,因此 Google 会对此进行搜索。您可能会找到一些适合您需求的软件包。

0

您必须首先构建 vite 文件(npm run build),然后将它们包含在邮件模板中。或者您可以将它们内联在一个大的<style>块中。

如果你想要一个更好的例子,看看welcome.blade.php如何在新的 Laravel 安装中做到这一点。

本站系公益性非盈利分享网址,本文来自用户投稿,不代表码文网立场,如若转载,请注明出处

(230)
如何在w3schoolcss框架中自定义 w3-button-hover类
上一篇
HTML中id属性的有效值是什么
下一篇

相关推荐

发表评论

登录 后才能评论

评论列表(77条)