GithubHelp home page GithubHelp logo

babel-plugin-inferno's Introduction

Inferno

Downloads Version License

InfernoJS Babel Plugin

Plugin for babel 6+ to enable JSX for Inferno

This plugin transforms JSX code in your projects to Inferno compatible virtual DOM. It is recommended to use this plugin for compiling JSX for inferno. It is different to other JSX plugins, because it outputs highly optimized inferno specific createVNode calls. This plugin also checks children shape during compilation stage to reduce overhead from runtime application.

How to install

Note! Make sure babel-plugin has same major version as the inferno you are using!

npm i --save-dev babel-plugin-inferno

How to use

Add the plugin to your package.json and update the plugin section in your .babelrc file. Or if your Babel settings are located inside the package.json - update the plugin section there.

It's important that you also include the babel-plugin-syntax-jsxplugin.

Example on a .babelrc file that will work with Inferno:

Make sure inferno plugin is added before babel module transformers

{   
    "presets": [ "es2015" ],
    "plugins": [["babel-plugin-inferno", {"imports": true}]]
}

Examples

// Render a simple div
Inferno.render(<div></div>, container);

// Render a div with text
Inferno.render(<div>Hello world</div>, container);

// Render a div with a boolean attribute
Inferno.render(<div autoFocus='true' />, container);

Special flags

This plugin provides few special compile time flags that can be used to optimize an inferno application.

// ChildFlags:
<div $HasVNodeChildren /> - Children is another vNode (Element or Component)
<div $HasNonKeyedChildren /> - Children is always array without keys
<div $HasKeyedChildren /> - Children is array of vNodes having unique keys
<div $ChildFlag={expression} /> - This attribute is used for defining children shpae runtime. See inferno-vnode-flags (ChildFlags) for possibe values

// Functional flags
<div $ReCreate /> - This flag tells inferno to always remove and add the node. It can be used to replace key={Math.random()}

Flag called noNormalize has been removed in v4, and is replaced by $HasVNodeChildren

Options

Change in v4:

Imports (boolean)

By default babel-plugin-inferno uses imports. That means you no longer need to import inferno globally. Just import the inferno specific code YOUR code uses.

example:

import {render} from 'inferno'; // Just import what you need, (render in this case)

// The plugin will automatically import, createVNode
render(<div>1</div>, document.getElementById('root'));

You need to have support for ES6 modules for this to work. If you are using legacy build system or outdated version of webpack, you can revert this change by using imports: false

{
    "presets": [ "es2015" ],
    "plugins": [["inferno", {
        "imports": false
    }]]
}

Pragma

Each method that is used from inferno can be replaced by custom name.

pragma (string) defaults to createVNode.

pragmaCreateComponentVNode (string) defaults to createComponentVNode.

pragmaNormalizeProps (string) defaults to normalizeProps.

pragmaTextVNode (string) defaults to createTextVNode.

{
    "presets": [ "es2015" ],
    "plugins": [["inferno", {
        "imports": true,
        "pragma": "",
        "pragmaCreateComponentVNode": "",
        "pragmaNormalizeProps": "",
        "pragmaTextVNode": ""
    }]]
}

babel-plugin-inferno's People

Contributors

4leem avatar annothernother avatar calebmer avatar callumlocke avatar havunen avatar hoistedvar avatar insin avatar lukeed avatar mstijak avatar nightwolfz avatar sandersky avatar trueadm avatar zerkalica avatar

Watchers

 avatar  avatar

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.