Giter Site home page Giter Site logo

mailwind's Introduction

Mailwind

Use Tailwind CSS to design HTML emails.

Tailwind makes it very easy to design websites, why not use it to design HTML emails? I've been using this for volt.fm and pikaso.me and it has made my life a lot easier.

Install

npm install -g mailwind

Usage

Design your HTML email using the Tailwind utility classes like you normally would for the web.

Then run the following command to generate the corresponding CSS file:

mailwind --input-html email.html --output-css style.css

Or run this command to generate an inlined HTML file:

mailwind --input-html email.html --output-html email-inlined.html

Options

--input-css

The path to your base CSS file. Use this if you need to write custom CSS. Defaults to style.css.

--input-html

The path to your HTML email file.

--output-css

The path to the CSS file that will be generated.

--output-html

The path to the inlined HTML file that will be generated.

--tailwind-config

The path to your custom Tailwind configuration file. Defaults to tailwind.config.js.

Note

In the provided default config file, all the units are changed to pixel which is probably what you want for HTML emails.

Example

Given an email.html file with this content:

<html>
  <body>
    <p class="font-bold text-lg">Welcome</p>
  </body>
</html>

running this command:

mailwind \
  --input-html email.html \
  --output-css style.css \
  --output-html email-inlined.html

will generate the following CSS and inlined HTML files:

.text-lg {
  font-size: 18px
}

.font-bold {
  font-weight: 700
}
<html>
  <body>
    <p class="font-bold text-lg" style="font-size: 18px; font-weight: 700;">Welcome</p>
  </body>
</html>

Version History

  • 2.2
    • Tailwind CSS is now a peer dependency so you can npm install newer versions if you need to (Thanks Songkeys)
  • 2.1
    • Colors are now generated without using CSS variables
    • Upgrade to Tailwind CSS v3.2
  • 2.0
    • New design
    • Upgrade to Tailwind CSS v3
  • 1.0
    • Initial release

Author

Soheil Rashidi

Copyright and License

Copyright 2022 Soheil Rashidi.

Licensed under the The MIT License (the "License"); you may not use this work except in compliance with the License. You may obtain a copy of the License in the LICENSE file, or at:

http://www.opensource.org/licenses/mit-license.php

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

mailwind's People

Contributors

alexferrari88 avatar soheilpro avatar songkeys avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mailwind's Issues

Currently requires all of the project's PostCSS plugins to be installed globally... why?

I found out about this utility today on StackShare's daily email and instantly wanted to try it out! Got it all setup in my project and ran into some errors running it until I installed all of the PostCSS plugins my project was using globally.

yarn global add postcss autoprefixer

Note, I was running the mailwind command from a node.js script making a call to child_process.execSync(), so I could generate all the inlined email templates in one swoop, so I don't know if that makes a difference or not to whether the dependencies need to be installed globally.

Custom Font CSS from tailwind.config.js

I want to create custom font css im importing from another file, but that wont work unfortunately.
There are no .font-{custom fontname} classes in my css.

.

.

Allow the usage of conditional breakpoint styling

I want to use breakpoint styling in my mail templates, like this:

<div class="flex w-full flex-col items-start gap-3 md:flex-row md:justify-between">

... but mailwind generates following snippet from this line:

<div class="flex w-full flex-col items-start gap-3 md:flex-row md:justify-between" style="box-sizing: border-box; border-width: 0; border-style: solid; border-color: #e5e7eb; --tw-translate-x: 0; --tw-translate-y: 0; --tw-rotate: 0; --tw-skew-x: 0; --tw-skew-y: 0; --tw-scale-x: 1; --tw-scale-y: 1; --tw-scroll-snap-strictness: proximity; --tw-ring-offset-width: 0px; --tw-ring-offset-color: #fff; --tw-ring-color: rgb(59 130 246 / 0.5); --tw-ring-offset-shadow: 0 0 #0000; --tw-ring-shadow: 0 0 #0000; --tw-shadow: 0 0 #0000; --tw-shadow-colored: 0 0 #0000; display: flex; width: 100%; flex-direction: column; align-items: flex-start; gap: 0.75rem;">

So I wonder if tailwind can also build these styles correctly?

feat: freemarker support

while working in java based envs, a lib called freemarker for generating html could be used. we are currelty looking for using mailwind to generate the templates here.

We would like it, if .ftl files can also get parsed by the mailwind lib, without issues.
we currelty discovered the following misbehaviors:

  • .ftl commands are parsed as comments => <#if> =>

this would be great <3

How to make this work?

Thanks a lot for the package but the usage instructions are not clear at all. I have Juice installed, but then how do I pass the css file into it to render the email?

const TestMail = () => {
  return (
    <div>
      <head>
        <link rel="stylesheet" href="index.css" />
      </head>
      <h1 className="text-xl font-bold border-b">You have a new Test Email on Productlane</h1>
      <p className="border-b">Something something</p>
      <a href="https://productlane.io/feedback" className="bg-purple-600">
        Open
      </a>
    </div>
  )
}

export function testMailer({ to }: IParams) {
  const emailHtml = ReactDOMServer.renderToStaticMarkup(<TestMail />)
  const processedHtml = juice(emailHtml, {
    webResources: {
      relativeTo: "../app/core/styles/",
    },
  })

// ...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.