Skip to content

Babel plugin to inject JSX from external file.

License

MIT, MIT licenses found

Licenses found

MIT
LICENSE
MIT
LICENSE.md
Notifications You must be signed in to change notification settings

hrgdavor/babel-plugin-jsx-inject

Repository files navigation

babel-plugin-jsx-inject CircleCI

Babel plugin to inject JSX from external file.

Can be combined with babel-plugin-jsx-simple and babel-plugin-jsx-translate

Used in mi2js library.

Usage

Used with babel by adding plugin to .babelrc

{
    plugins: ["jsx-inject"]
}

The plugin replaces occurrence of an return <template/> statement with JSX from external file.

If you jou have a file sample.js with:

//...
    function myFunc(h){
        return <template/>
    }
//...

and template file sample.tpl in the same folder

<div>
    <h1>Title</h1>
    <p>{state.text}</p>
</div>

the sample.tpl will be injected in the sample.js resulting in something like this

//...
    function myFunc(h){
        return <div>
            <h1>Title</h1>
            <p>{state.text}</p>
        </div>
    }
//...

arrow expression

it is good to know that for purpose of catching a return statement, an arrow expression like:

applyHtml( h=><template/> );

is pretty much the same (except of arrow expression scoping) as:

applyHtml( function(h){ return <template/>;} );

About

Babel plugin to inject JSX from external file.

Resources

License

MIT, MIT licenses found

Licenses found

MIT
LICENSE
MIT
LICENSE.md

Stars

Watchers

Forks

Packages

No packages published