Skip to content
This repository has been archived by the owner on Oct 14, 2018. It is now read-only.

MunGell/babel-plugin-template-string-processing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Template String Transformation Babel plugin

This plugin allows you to process Template Strings with any transformers defined in .babelrc file based on string prefix. Please note that transformers will be applied in the same order they listed in configuration.

Example

.babelrc configuration:

{
    "plugins": [
        "babel-plugin-template-string-processing"
    ],
    "extra": {
        "babel-plugin-template-string-processing": [
            {
                "type": "postcss",
                "options": [
                    "postcss-nested",
                    ["autoprefixer", { browsers: ['last 10 versions'] }]
                ]
            }
        ]
    }
}

Template String in JavaScript file:

function style() {

    return `~postcss
        .block {
            display: flex;

            &__element {

            }
        }
    `;

}

Result:

function style() {
    return '.block { display: -webkit-box; display: -webkit-flex; display: -ms-flexbox; display: flex; } .block__element {}';
}

Please not how transformer prefix (type in plugin configuration) starts with ~ character.

Available transformers

How to write your own transformer

Transformer is a simple function that takes string (code) and tranformer options as parameters and returns processed string.

About

Babel plugin to work with simple template strings. Experimental code that evolved to https://github.com/digitalie/one-loader

Resources

Stars

Watchers

Forks

Packages

No packages published