Gathering detailed insights and metrics for inferno
Gathering detailed insights and metrics for inferno
Gathering detailed insights and metrics for inferno
Gathering detailed insights and metrics for inferno
🔥 An extremely fast, React-like JavaScript library for building modern user interfaces
npm install inferno
Typescript
Module System
Node Version
NPM Version
JavaScript (99.5%)
HTML (0.46%)
CSS (0.04%)
Total Downloads
21,450,562
Last Day
3,120
Last Week
127,649
Last Month
545,545
Last Year
6,555,801
16,098 Stars
6,289 Commits
634 Forks
266 Watching
6 Branches
193 Contributors
Minified
Minified + Gzipped
Latest Version
8.2.3
Package Id
inferno@8.2.3
Unpacked Size
642.01 kB
Size
135.92 kB
File Count
36
NPM Version
lerna/6.6.2/node@v21.4.0+x64 (linux)
Node Version
21.4.0
Publised On
10 Dec 2023
Cumulative downloads
Total Downloads
Last day
-6.9%
3,120
Compared to previous day
Last week
-6.9%
127,649
Compared to previous week
Last month
-13.7%
545,545
Compared to previous month
Last year
8.3%
6,555,801
Compared to previous year
3
2
Inferno is an insanely fast, React-like library for building high-performance user interfaces on both the client and server.
The main objective of the InfernoJS project is to provide the fastest possible runtime performance for web applications. Inferno excels at rendering real time data views or large DOM trees.
The performance is achieved through multiple optimizations, for example:
createVNode
calls, instead of createElement
linkEvent
feature removes the need to use arrow functions or binding event callbacksinferno-server
createPortal
- API<div style="background-color: red"></div>
or using object literal syntax <div style={{"background-color": "red"}}></div>
. For camelCase syntax support see inferno-compat
.Since version 4 we have started running our test suite without any polyfills. Inferno is now part of Saucelabs open source program and we use their service for executing the tests.
InfernoJS is actively tested with browsers listed below, however it may run well on older browsers as well. This is due to limited support of browser versions in recent testing frameworks. https://github.com/jasmine/jasmine/blob/main/release_notes/5.0.0.md
Live examples at https://infernojs.github.io/inferno
Let's start with some code. As you can see, Inferno intentionally keeps the same design ideas as React regarding components: one-way data flow and separation of concerns.
In these examples, JSX is used via the Inferno JSX Babel Plugin to provide a simple way to express Inferno virtual DOM. You do not need to use JSX, it's completely optional, you can use hyperscript or createElement (like React does). Keep in mind that compile time optimizations are available only for JSX.
1import { render } from 'inferno'; 2 3const message = "Hello world"; 4 5render( 6 <MyComponent message={ message } />, 7 document.getElementById("app") 8);
Furthermore, Inferno also uses ES6 components like React:
1import { render, Component } from 'inferno'; 2 3class MyComponent extends Component { 4 constructor(props) { 5 super(props); 6 this.state = { 7 counter: 0 8 }; 9 } 10 render() { 11 return ( 12 <div> 13 <h1>Header!</h1> 14 <span>Counter is at: { this.state.counter }</span> 15 </div> 16 ); 17 } 18} 19 20render( 21 <MyComponent />, 22 document.getElementById("app") 23);
Because performance is an important aspect of this library, we want to show you how to optimize your application even further.
In the example below we optimize diffing process by using JSX $HasVNodeChildren and $HasTextChildren to predefine children shape compile time.
In the MyComponent render method there is a div that contains JSX expression node
as its content. Due to dynamic nature of Javascript
that variable node
could be anything and Inferno needs to go through the normalization process to make sure there are no nested arrays or other invalid data.
Inferno offers a feature called ChildFlags for application developers to pre-define the shape of vNode's child node. In this example case
it is using $HasVNodeChildren
to tell the JSX compiler, that this vNode contains only single element or component vNode.
Now inferno will not go into the normalization process runtime, but trusts the developer decision about the shape of the object and correctness of data.
If this contract is not kept and node
variable contains invalid value for the pre-defined shape (fe. null
), then application would crash runtime.
There is also span-element in the same render method, which content is set dynamically through _getText()
method. There $HasTextChildren
child-flag
fits nicely, because the content of that given "span" is never anything else than text.
All the available child flags are documented here.
1import { createTextVNode, render, Component } from 'inferno'; 2 3class MyComponent extends Component { 4 constructor(props) { 5 super(props); 6 this.state = { 7 counter: 0 8 }; 9 } 10 11 _getText() { 12 return 'Hello!'; 13 } 14 15 render() { 16 const node = this.state.counter > 0 ? <div>0</div> : <span $HasTextChildren>{this._getText()}</span>; 17 18 return ( 19 <div> 20 <h1>Header!</h1> 21 <div $HasVNodeChildren>{node}</div> 22 </div> 23 ); 24 } 25} 26 27render( 28 <MyComponent />, 29 document.getElementById("app") 30);
To tear down inferno application you need to render null on root element.
Rendering null
will trigger unmount lifecycle hooks for whole vDOM tree and remove global event listeners.
It is important to unmount unused vNode trees to free browser memory.
1import { createTextVNode, render, Component } from 'inferno'; 2 3const rootElement = document.getElementById("app"); 4 5// Start the application 6render( 7 <ExampleComponent/>, 8 rootElement 9); 10 11// Tear down 12render( 13 null, 14 rootElement 15); 16
If you have built something using Inferno you can add them here:
The easiest way to get started with Inferno is by using Create Inferno App.
Alternatively, you can try any of the following:
Core package:
1npm install --save inferno
Addons:
1# server-side rendering 2npm install --save inferno-server 3# routing 4npm install --save inferno-router
Pre-bundled files for browser consumption can be found on our cdnjs:
Or on jsDelivr:
https://cdn.jsdelivr.net/npm/inferno@latest/dist/inferno.min.js
Or on unpkg.com:
https://unpkg.com/inferno@latest/dist/inferno.min.js
1npm install --save-dev babel-plugin-inferno
1npm install --save inferno-hyperscript
1npm install --save inferno-create-element
1npm install --save-dev inferno-compat
Note: Make sure you read more about inferno-compat
before using it.
Inferno now has bindings available for some of the major state management libraries out there:
inferno-redux
inferno-mobx
@cerebral/inferno
Inferno has its own JSX Babel plugin.
onClick
).createRef
or callback ref
APIinput
/select
/textarea
elements. This prevents lots of edgecases where the virtual DOM is not the source of truth (it should always be). Preact pushes the source of truth to the DOM itself.Like React, Inferno also uses a light-weight synthetic event system in certain places (although both event systems differ massively). Inferno's event system provides highly efficient delegation and an event helper called linkEvent
.
One major difference between Inferno and React is that Inferno does not rename events or change how they work by default. Inferno only specifies that events should be camel cased, rather than lower case. Lower case events will bypass
Inferno's event system in favour of using the native event system supplied by the browser. For example, when detecting changes on an <input>
element, in React you'd use onChange
, with Inferno you'd use onInput
instead (the
native DOM event is oninput
).
Available synthetic events are:
onClick
onDblClick
onFocusIn
onFocusOut
onKeyDown
onKeyPress
onKeyUp
onMouseDown
onMouseMove
onMouseUp
onTouchEnd
onTouchMove
onTouchStart
linkEvent
(package: inferno
)linkEvent()
is a helper function that allows attachment of props
/state
/context
or other data to events without needing to bind()
them or use arrow functions/closures. This is extremely useful when dealing with events in functional components. Below is an example:
1import { linkEvent } from 'inferno';
2
3function handleClick(props, event) {
4 props.validateValue(event.target.value);
5}
6
7function MyComponent(props) {
8 return <div><input type="text" onClick={ linkEvent(props, handleClick) } /><div>;
9}
This is an example of using it with ES2015 classes:
1import { linkEvent, Component } from 'inferno'; 2 3function handleClick(instance, event) { 4 instance.setState({ data: event.target.value }); 5} 6 7class MyComponent extends Component { 8 render () { 9 return <div><input type="text" onClick={ linkEvent(this, handleClick) } /><div>; 10 } 11}
linkEvent()
offers better performance than binding an event in a class constructor and using arrow functions, so use it where possible.
In HTML, form elements such as <input>
, <textarea>
, and <select>
typically maintain their own state and update it based on user input.
In Inferno, mutable state is typically kept in the state property of components, and only updated with setState()
.
We can combine the two by making the Inferno state be the "single source of truth". Then the Inferno component that renders a form also controls what happens in that form on subsequent user input. An input form element whose value is controlled by Inferno in this way is called a "controlled component".
render
(package: inferno
)1import { render } from 'inferno'; 2 3render(<div />, document.getElementById("app"));
Render a virtual node into the DOM in the supplied container given the supplied virtual DOM. If the virtual node was previously rendered into the container, this will perform an update on it and only mutate the DOM as necessary, to reflect the latest Inferno virtual node.
Warning: If the container element is not empty before rendering, the content of the container will be overwritten on the initial render.
createRenderer
(package: inferno
)createRenderer
creates an alternative render function with a signature matching that of the first argument passed to a reduce/scan function. This allows for easier integration with reactive programming libraries, like RxJS and Most.
1import { createRenderer } from 'inferno'; 2import { scan, map } from 'most'; 3 4const renderer = createRenderer(); 5 6 7// NOTE: vNodes$ represents a stream of virtual DOM node updates 8scan(renderer, document.getElementById("app"), vNodes$);
See inferno-most-fp-demo for an example of how to build an app architecture around this.
createElement
(package: inferno-create-element
)Creates an Inferno VNode using a similar API to that found with React's createElement()
1import { Component, render } from 'inferno'; 2import { createElement } from 'inferno-create-element'; 3 4class BasicComponent extends Component { 5 render() { 6 return createElement('div', { 7 className: 'basic' 8 }, 9 createElement('span', { 10 className: this.props.name 11 }, 'The title is ', this.props.title) 12 ) 13 } 14} 15 16render( 17 createElement(BasicComponent, { title: 'abc' }), 18 document.getElementById("app") 19);
Component
(package: inferno
)Class component:
1import { Component } from 'inferno'; 2 3class MyComponent extends Component { 4 render() { 5 return <div>My Component</div> 6 } 7}
This is the base class for Inferno Components when they're defined using ES6 classes.
Functional component:
1const MyComponent = ({ name, age }) => ( 2 <span>My name is: { name } and my age is: {age}</span> 3);
Another way of using defaultHooks.
1export function Static() { 2 return <div>1</div>; 3} 4 5Static.defaultHooks = { 6 onComponentShouldUpdate() { 7 return false; 8 } 9};
Default props
1export function MyFunctionalComponent({value}) { 2 return <div>{value}</div>; 3} 4 5MyFunctionalComponent.defaultProps = { 6 value: 10 7}; 8
Functional components are first-class functions where their first argument is the props
passed through from their parent.
createVNode
(package: inferno
)1import { createVNode } from 'inferno'; 2 3createVNode( 4 flags, 5 type, 6 [className], 7 [...children], 8 [childFlags], 9 [props], 10 [key], 11 [ref] 12)
createVNode is used to create html element's virtual node object. Typically createElement()
(package: inferno-create-element
), h()
(package: inferno-hyperscript
) or JSX are used to create
VNode
s for Inferno, but under the hood they all use createVNode()
. Below is an example of createVNode
usage:
1import { VNodeFlags, ChildFlags } from 'inferno-vnode-flags'; 2import { createVNode, createTextVNode, render } from 'inferno'; 3 4const vNode = createVNode(VNodeFlags.HtmlElement, 'div', 'example', createTextVNode('Hello world!'), ChildFlags.HasVNodeChildren); 5 6// <div class="example">Hello world!</div> 7 8render(vNode, container);
createVNode
arguments explained:
flags
: (number) is a value from VNodeFlags
, this is a numerical value that tells Inferno what the VNode describes on the page.
type
: (string) is tagName for element for example 'div'
className
: (string) is the class attribute ( it is separated from props because it is the most commonly used property )
children
: (vNode[]|vNode) is one or array of vNodes to be added as children for this vNode
childFlags
: (number) is a value from ChildFlags
, this tells inferno shape of the children so normalization process can be skipped.
props
: (Object) is object containing all other properties. fe: {onClick: method, 'data-attribute': 'Hello Community!}
key
: (string|number) unique key within this vNodes siblings to identify it during keyed algorithm.
ref
: (function) callback which is called when DOM node is added/removed from DOM.
createComponentVNode
(package: 'inferno')1import { createComponentVNode } from 'inferno'; 2 3createComponentVNode( 4 flags, 5 type, 6 [props], 7 [key], 8 [ref] 9)
createComponentVNode is used for creating vNode for Class/Functional Component.
Example:
1import { VNodeFlags, ChildFlags } from 'inferno-vnode-flags'; 2import { createVNode, createTextVNode, createComponentVNode, render } from 'inferno'; 3 4function MyComponent(props, context) { 5 return createVNode(VNodeFlags.HtmlElement, 'div', 'example', createTextVNode(props.greeting), ChildFlags.HasVNodeChildren); 6} 7 8const vNode = createComponentVNode(VNodeFlags.ComponentFunction, MyComponent, { 9 greeting: 'Hello Community!' 10}, null, { 11 onComponentDidMount() { 12 console.log("example of did mount hook!") 13 } 14}) 15 16// <div class="example">Hello Community!</div> 17 18render(vNode, container);
createComponentVNode
arguments explained:
flags
: (number) is a value from VNodeFlags
, this is a numerical value that tells Inferno what the VNode describes on the page.
type
: (Function/Class) is the class or function prototype for Component
props
: (Object) properties passed to Component, can be anything
key
: (string|number) unique key within this vNodes siblings to identify it during keyed algorithm.
ref
: (Function|Object) this property is object for Functional Components defining all its lifecycle methods. For class Components this is function callback for ref.
createTextVNode
(package: 'inferno')createTextVNode is used for creating vNode for text nodes.
createTextVNode
arguments explained:
text: (string) is a value for text node to be created.
key: (string|number) unique key within this vNodes siblings to identify it during keyed algorithm.
1import { createTextVNode } from 'inferno'; 2 3createTextVNode( 4 text, 5 key 6)
cloneVNode
(package: inferno-clone-vnode
)This package has same API as React.cloneElement
1import { cloneVNode } from 'inferno-clone-vnode'; 2 3cloneVNode( 4 vNode, 5 [props], 6 [...children] 7)
Clone and return a new Inferno VNode
using a VNode
as the starting point. The resulting VNode
will have the original VNode
's props with the new props merged in shallowly. New children will replace existing children. key and ref from the original VNode
will be preserved.
cloneVNode()
is almost equivalent to:
1<VNode.type {...VNode.props} {...props}>{children}</VNode.type>
An example of using cloneVNode
:
1import { createVNode, render } from 'inferno'; 2import { cloneVNode } from 'inferno-clone-vnode'; 3import { VNodeFlags } from 'inferno-vnode-flags'; 4 5const vNode = createVNode(VNodeFlags.HtmlElement, 'div', 'example', 'Hello world!'); 6const newVNode = cloneVNode(vNode, { id: 'new' }); // we are adding an id prop to the VNode 7 8render(newVNode, container);
If you're using JSX:
1import { render } from 'inferno'; 2import { cloneVNode } from 'inferno-clone-vnode'; 3 4const vNode = <div className="example">Hello world</div>; 5const newVNode = cloneVNode(vNode, { id: 'new' }); // we are adding an id prop to the VNode 6 7render(newVNode, container);
createPortal
(package: 'inferno')HTML:
1<div id="root"></div> 2<div id="outside"></div>
Javascript:
1const { render, Component, version, createPortal } from 'inferno'; 2 3function Outsider(props) { 4 return <div>{`Hello ${props.name}!`}</div>; 5} 6 7const outsideDiv = document.getElementById('outside'); 8const rootDiv = document.getElementById('root'); 9 10function App() { 11 return ( 12 <div> 13 Main view 14 ... 15 {createPortal(<Outsider name="Inferno" />, outsideDiv)} 16 </div> 17 ); 18} 19 20 21// render an instance of Clock into <body>: 22render(<App />, rootDiv);
Results into:
1<div id="root"> 2 <div>Main view ...</div> 3</div> 4<div id="outside"> 5 <div>Hello Inferno!</div> 6</div>
Cool, huh? Updates (props/context) will flow into "Outsider" component from the App component the same way as any other Component. For inspiration on how to use it click here!
createRef
(package: inferno
)createRef API provides shorter syntax than callback ref when timing of element is not needed.
1import { Component, render, createRef } from 'inferno'; 2 3class Foobar extends Component { 4 constructor(props) { 5 super(props); 6 7 // Store reference somewhere 8 this.element = createRef(); // Returns object {current: null} 9 } 10 11 render() { 12 return ( 13 <div> 14 <span id="span" ref={this.element}> 15 Ok 16 </span> 17 </div> 18 ); 19 } 20} 21 22render(<Foobar />, container);
createFragment
(package: inferno
)createFragment is the native way to createFragment vNode. createFragment(children: any, childFlags: ChildFlags, key?: string | number | null)
createFragment
arguments explained:
children
: (Array) Content of fragment vNode, typically array of VNodes
childFlags
: (number) is a value from ChildFlags
, this tells inferno shape of the children so normalization process can be skipped.
key
: (string|number) unique key within this vNodes siblings to identify it during keyed algorithm.
Alternative ways to create fragment vNode are:
<> ... </>
, <Fragment> .... </Fragment>
or <Inferno.Fragment> ... </Inferno.Fragment>
createElement(Inferno.Fragment, {key: 'test'}, ...children)
h(Inferno.Fragment, {key: 'test'}, children)
In the below example both fragments are identical except they have different key
1import { Fragment, render, createFragment } from 'inferno'; 2import { ChildFlags } from 'inferno-vnode-flags'; 3 4function Foobar() { 5 return ( 6 <div $HasKeyedChildren> 7 {createFragment( 8 [<div>Ok</div>, <span>1</span>], 9 ChildFlags.HasNonKeyedChildren, 10 'key1' 11 )} 12 <Fragment key="key2"> 13 <div>Ok</div> 14 <span>1</span> 15 </Fragment> 16 </div> 17 ); 18} 19 20render(<Foobar />, container);
forwardRef
(package: inferno
)forwardRef is a new mechanism to "forward" ref inside a functional Component. It can be useful if you have simple functional Components and you want to create reference to a specific element inside it.
1import { forwardRef, Component, render } from 'inferno'; 2 3const FancyButton = forwardRef((props, ref) => ( 4 <button ref={ref} className="FancyButton"> 5 {props.children} 6 </button> 7)); 8 9class Hello extends Component { 10 render() { 11 return ( 12 <FancyButton 13 ref={btn => { 14 if (btn) { 15 // btn variable is the button rendered from FancyButton 16 } 17 }} 18 > 19 Click me! 20 </FancyButton> 21 ); 22 } 23} 24 25render(<Hello />, container);
hydrate
(package: inferno-hydrate
)1import { hydrate } from 'inferno-hydrate'; 2 3hydrate(<div />, document.getElementById("app"));
Same as render()
, but is used to hydrate a container whose HTML contents were rendered by inferno-server
. Inferno will attempt to attach event listeners to the existing markup.
options.componentComparator
( package inferno
) DEV onlyThis option can be used during development to create custom component comparator method.
This option will be called on every Component update.
It gets two parameters: lastVNode and nextVNode. When it returns true
lastVNode will be replaced with nextVNode.
If anything else than true
is returned it falls to normal behavior.
1import {options} from 'inferno'; 2 3options.componentComparator = function (lastVNode, nextVNode) { 4 /* custom logic */ 5 return true; // Replaces lastVNode with nextVNode 6}
findDOMNode
(package: inferno-extras
)This feature has been moved from inferno to inferno-compat in v6. No options are needed anymore.
Note: we recommend using a ref
callback on a component to find its instance, rather than using findDOMNode()
. findDOMNode()
cannot be used on functional components.
If a component has been mounted into the DOM, this returns the corresponding native browser DOM element. This method is useful for reading values out of the DOM, such as form field values and performing DOM measurements.
In most cases, you can attach a ref to the DOM node and avoid using findDOMNode()
at all. When render returns null or false, findDOMNode()
returns null.
If Component has rendered fragment it returns the first element.
VNodeFlags:
VNodeFlags.HtmlElement
VNodeFlags.ComponentUnknown
VNodeFlags.ComponentClass
VNodeFlags.ComponentFunction
VNodeFlags.Text
VNodeFlags.SvgElement
VNodeFlags.InputElement
VNodeFlags.TextareaElement
VNodeFlags.SelectElement
VNodeFlags.Portal
VNodeFlags.ReCreate
(JSX $ReCreate) always re-creates the vNodeVNodeFlags.ContentEditable
VNodeFlags.Fragment
VNodeFlags.InUse
VnodeFlags.ForwardRef
VNodeFlags.Normalized
VNodeFlags Masks:
VNodeFlags.ForwardRefComponent
Functional component wrapped in forward refVNodeFlags.FormElement
- Is form elementVNodeFlags.Element
- Is vNode elementVNodeFlags.Component
- Is vNode ComponentVNodeFlags.DOMRef
- Bit set when vNode holds DOM referenceVNodeFlags.InUseOrNormalized
- VNode is used somewhere else or came from normalization processVNodeFlags.ClearInUseNormalized
- Opposite mask of InUse or NormalizedChildFlags
ChildFlags.UnknownChildren
needs NormalizationChildFlags.HasInvalidChildren
is invalid (null, undefined, false, true)ChildFlags.HasVNodeChildren
(JSX $HasVNodeChildren) is single vNode (Element/Component)ChildFlags.HasNonKeyedChildren
(JSX $HasNonKeyedChildren) is Array of vNodes non keyed (no nesting, no holes)ChildFlags.HasKeyedChildren
(JSX $HasKeyedChildren) is Array of vNodes keyed (no nesting, no holes)ChildFlags.HasTextChildren
(JSX $HasTextChildren) vNode contains only textChildFlags Masks
ChildFlags.MultipleChildren
Is ArrayrenderToString
(package: inferno-server
)1import { renderToString } from 'inferno-server'; 2 3const string = renderToString(<div />);
Render a virtual node into an HTML string, given the supplied virtual DOM.
Name | Triggered when | Arguments to callback |
---|---|---|
onComponentWillMount | a functional component is about to mount | |
onComponentDidMount | a functional component has mounted successfully | domNode |
onComponentShouldUpdate | a functional component has been triggered to update | lastProps, nextProps |
onComponentWillUpdate | a functional component is about to perform an update | lastProps, nextProps |
onComponentDidUpdate | a functional component has performed an update | lastProps, nextProps |
onComponentWillUnmount | a functional component is about to be unmounted | domNode |
onComponentDidAppear | a functional component has mounted and is ready for animations | domNode, props |
onComponentWillDisappear | a functional component is unmounted before DOM node is removed | domNode, props, callback |
onComponentWillDisappear has special type of argument "callback" which needs to be called when component is ready to be removed from the DOM. fe. after animations are finished.
All these Component lifecycle methods ( including render
and setState - callback
) are called with Component instance context. You don't need to "bind" these methods.
Name | Triggered when | Arguments to callback |
---|---|---|
componentDidMount | component has been mounted successfully | |
componentWillMount | component is about to mount | |
componentWillReceiveProps | before render when component updates | nextProps, context |
shouldComponentUpdate | component has been triggered to update | nextProps, nextState |
componentWillUpdate | component is about to perform an update | nextProps, nextState, context |
componentDidUpdate | component has performed an update | lastProps, lastState, snapshot |
componentWillUnmount | component is about to be unmounted | |
getChildContext | before render method, return value object is combined to sub tree context | |
getSnapshotBeforeUpdate | before component updates, return value is sent to componentDidUpdate as 3rd parameter | lastProps, lastState |
static getDerivedStateFromProps | before render method | nextProps, state |
componentDidAppear | component has mounted and is ready for animations | domNode |
componentWillDisappear | component is unmounted before DOM node is removed | domNode, callback |
componentWillDisappear has special type of argument "callback" which needs to be called when component is ready to be removed from the DOM. fe. after animations are finished.
Functional lifecycle events must be explicitly assigned via props onto a functional component like shown below:
1import { render } from 'inferno'; 2 3function mounted(domNode) { 4 // [domNode] will be available for DOM nodes and components (if the component has mounted to the DOM) 5} 6 7function FunctionalComponent({ props }) { 8 return <div>Hello world</div>; 9} 10 11render( 12 <FunctionalComponent onComponentDidMount={ mounted } />, 13 document.getElementById("app") 14);
Please note: class components (ES2015 classes) from inferno
do not support the same lifecycle events (they have their own lifecycle events that work as methods on the class itself).
By default, Inferno will run in development mode. Development mode provides extra checks and better error messages at the cost of slower performance and larger code to parse. When using Inferno in a production environment, it is highly recommended that you turn off development mode.
Ensure the environment variable process.env.NODE_ENV
is set to production
.
When building your application bundle, ensure process.env.NODE_ENV
is replaced with string"development"
or "production"
based on the workflow.
It is recommended to use ts-plugin-inferno for typescript TSX compilation and babel-plugin-infeno for javascript JSX compilation.
When building for development, you may want to use inferno.dev.esm.js
. That bundle file contains ES6 exports for better tree-shaking support, improved error messages and added validation to help fixing possible issues during development.
The file is found from package.json
- dev:module
entry point and the file is physically located in node_modules/inferno/dist/index.dev.esm.js
.
Remember that it is not recommended to use that file in production due to slower performance. For production usage use node_modules/inferno/dist/inferno.esm.js
file.
Example of Webpack configuration:
1const path = require('path'); 2const infernoTsx = require('ts-plugin-inferno').default; 3 4... webpack config ... 5 6 module: { 7 rules: [ 8 { 9 test: /\.js$/, // Add "jsx" if your application uses `jsx` file extensions 10 exclude: /node_modules/, 11 use: [{ 12 loader: 'babel-loader', 13 options: { 14 plugins: [ 15 // Compile javascript JSX syntax using inferno's own plugin 16 ['babel-plugin-inferno', {imports: true}] 17 ] 18 } 19 }] 20 }, 21 { 22 test: /\.ts+(|x)$/, // Compile ts and tsx extensions 23 exclude: /node_modules/, 24 use: [{ 25 loader: 'ts-loader', 26 options: { 27 getCustomTransformers: () => ({ 28 // inferno custom TSX plugin 29 after: [infernoTsx()] 30 }), 31 compilerOptions: { 32 /* typescript compiler options */ 33 } 34 } 35 }] 36 } 37 ] 38 }, 39 resolve: { 40 extensions: ['.js', '.ts', '.tsx'], 41 alias: { 42 // This maps import "inferno" to es6 module entry based on workflow 43 inferno: path.resolve(__dirname, 'node_modules/inferno/dist', isProduction ? 'index.dev.esm.js' : 'index.esm.js') 44 } 45 }, 46 plugins: [ 47 new webpack.DefinePlugin({ 48 'process.env': { 49 'NODE_ENV': JSON.stringify(isProduction ? 'production' : 'development') 50 } 51 }) 52 ]
Example of Rollup configuration:
1const path = require('path'); 2const alias = require('@rollup/plugin-alias'); 3const {babel} = require('@rollup/plugin-babel'); 4const replace = require('@rollup/plugin-replace'); 5const typescript = require('rollup-plugin-typescript2'); 6const transformInferno = require('ts-plugin-inferno').default; 7 8... Rollup config ... 9{ 10 input: /* entry file */, 11 plugins: [ 12 alias({ 13 resolve: ['.js'], 14 entries: [ 15 // This maps import "inferno" to es6 module entry based on workflow 16 {find: 'inferno', replacement: path.resolve(__dirname, 'node_modules/inferno/dist', isProduction ? 'index.dev.esm.js' : 'index.esm.js')} 17 ] 18 }), 19 typescript({ 20 include: ['*.ts+(|x)', '**/*.ts+(|x)'], 21 transformers: [ 22 () => ({ 23 after: [transformInferno()] 24 }) 25 ], 26 tsconfig: 'tsconfig.json', 27 tsconfigOverride: { 28 /* typescript compiler options */ 29 } 30 }), 31 babel({ 32 babelrc: false, 33 sourceMaps: isDeploy, 34 plugins: [ 35 // Compile javascript JSX syntax using inferno's own plugin 36 ['babel-plugin-inferno', {imports: true}] 37 ], 38 babelHelpers: 'bundled' 39 }) 40 ] 41}
Inferno always wants to deliver great performance. In order to do so, it has to make intelligent assumptions about the state of the DOM and the elements available to mutate. Custom namespaces conflict with this idea and change the schema of how different elements and attributes might work, so Inferno makes no attempt to support namespaces. Instead, SVG namespaces are automatically applied to elements and attributes based on their tag name
.
If you want to contribute code, fork this project and submit a PR from your fork. To run browser tests you need to build the repos. A complete rebuild of the repos can take >5 mins.
1$ git clone git@github.com:infernojs/inferno.git 2$ cd inferno && npm i 3$ npm run test:node 4$ npm run build 5$ npm run test:browser
If you only want to run the browser tests when coding, use the following to reduce turnaround by 50-80%:
1$ npm run quick-test:browser # Compiles all packages and runs browser tests 2$ npm run quick-test:browser-inferno # Only compiles the inferno package and runs browser tests 3$ npm run quick-test:browser-debug # Compiles all packages and runs browser tests with "debug"
There is an InfernoJS Discord. You can join via https://discord.gg/SUKuhgaBpF.
This project exists thanks to all the people who contribute. [Contribute].
Thank you to all our backers! 🙏 [Become a backer]
Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]
No vulnerabilities found.
Reason
13 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 10
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
SAST tool is run on all commits
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
Found 2/30 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
24 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-12-16
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More