Babel plugin (experimental đź’€) to transform ES6 template strings before compilation to ES5
JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
transforms
README.md
index.js
package.json
util.js

README.md

babel-plugin-template-string-transform

Install

npm install --save html-minifier cssmin

npm install --save WebEngage/babel-plugin-template-string-transform

Use

build.js

var babel = require('babel-core')

var transformed = babel.transform('code();', {
    plugins: [
        [
            'template-string-transform',
            {
                htmlmin : require('babel-plugin-template-string-transform/transforms/minify-html'),
                cssmin  : require('babel-plugin-template-string-transform/transforms/minify-css')
            }
        ]
    ],
    presets: ['es2015']
})

...

source.js

var Layout = {
    getMarkup: function (data) {
        return htmlmin`
          <div id="wrapper">
              <div id="cta">
                  <a href="${data.href}"></a>
              </div>
          </div>
        `
    },
    getStyles: function (data) {
        return cssmin`
            div#cta a {
                color: ${data.linkColor};
            }
        `
    }
}