Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

A blazing fast React alternative, compatible with IE8 and React 16.

License

NotificationsYou must be signed in to change notification settings

NervJS/nerv

Repository files navigation

Build StatusLicenseCoverage StatusDownloadsBuild StatusSauce Test Status

Nerv is a virtual-dom based JavaScript (TypeScript) library with identical React 16 API, which offers much higher performance, tinier package size and better browser compatibility.

中文

Features

⚛ Identical React API, no 'nerv-compat' is needed

️⚔ Battle tested, serve inJD.com home page andTOPLIFE.com

⚡️ High performance

🤣 IE8 compatibility

🎯 Tiny size, 9Kb gzipped

🌗 Isomorphic rendering on both client and server

💫 Support React 16 features, Error Boundaries, Portals, custom DOM attributes, etc.

Packages

This repository is a monorepo that we manage usingLerna. That means that we actually publishseveral packages to npm from the same codebase, including:

PackageDescription
nervjsThe core of Nerv
nerv-reduxNerv binding for Redux
nerv-devtoolsProvides support for React's Dev Tools for Nerv
nerv-serverSupport for server side rendering
nerv-test-utilsSuite of utilities for testing Nerv applications
nerv-utilsInternal Helpers functions for Nerv
nerv-sharedInternal shared functions for Nerv
nerv-create-classThe legacycreateClass API for Nerv

Getting Started

The easiest way to get started with Nerv is usingCodeSandbox Playground, If you use React, you already know how to use Nerv.

Install

Of course we recommend that you use Nerv withWebpack andBabel.First you can install Nerv like this

With npm

$ npm install --save nervjs

With yarn

$ yarn add nervjs

Usage

Import what you need. Nerv provides both named and default exports, you can use Nerv as a namespace or simply import what you need as locals.

Default exports:

importNervfrom'nervjs'classHelloMessageextendsNerv.Component{render(){return<div>Hello{this.props.name}</div>}}Nerv.render(<HelloMessagename="Nerv"/>,document.getElementById('app'))

Named:

import{Component,render}from'nervjs'classHelloMessageextendsComponent{render(){return<div>Hello{this.props.name}</div>}}render(<HelloMessagename="Nerv"/>,document.getElementById('app'))

☝️ For more information please move to the officialdevelopment document

Examples

Switching to Nerv from React

Switching to Nerv from React is easy as adding aliasnervjs forreact andreact-dom. No changes in code needed.

Usage with Webpack

Add an alias in yourwebpack.config.js:

{// ...resolve:{alias:{'react':'nervjs','react-dom':'nervjs',// Not necessary unless you consume a module using `createClass`'create-react-class':"nerv-create-class"}}// ...}

Usage with Babel

Install the babel plugin for aliasing

$ npm install --save-dev babel-plugin-module-resolver

In.babelrc:

{"plugins":[["module-resolver",{"root":["."],"alias":{"react":"nervjs","react-dom":"nervjs",// Not necessary unless you consume a module using `createClass`"create-react-class":"nerv-create-class"}}]]}

Usage with Browserify

Install the aliasify transform:

$ npm i --save-dev aliasify

Then in yourpackage.json:

{"aliasify":{"aliases":{"react":"nervjs","react-dom":"nervjs"}}}

Compatible with React

Nerv currently support React API and features:

react

  • React.createClass (legacy)
  • React.createElement
  • React.cloneElement
  • React.Component
  • React.PureComponent
  • React.PropTypes
  • React.Children
  • React.isValidElement
  • React.createFactory
  • Error Boundaries (React 16)

react-dom

  • React.unstable_renderSubtreeIntoContainer (legacy)
  • ReactDOM.render
  • ReactDOM.unmountComponentAtNode
  • ReactDOM.findDOMNode
  • ReactDOM.hydrate (React 16)
  • ReactDOM.createPortal (React 16)

Internet Explorer 8 (or below) compatibility

First, installes5-polyfill:

npm install --save es5-polyfill

Then insert the code into the beginning of your entry file:

require('es5-polyfill');

At last, setting.babelrc if you are usingbabel:

{"presets":[["env",{"spec":true,"useBuiltIns":false}],["es3"]],  ...}

Developer Tools

Nerv has a development tools module which allows you to inspect the component hierarchies via theReact Chrome Developer Tools plugin.

To enable the Nerv development tools you must install thenerv-devtools module and thenrequire('nerv-devtools') before the initialNerv.render().

if(process.env.NODE_ENV!=='production'){require('nerv-devtools')}// before Nerv.render()Nerv.render(<App/>,document.getElementById('#root'))

nerv-devtools

Acknowledgement

AOTU.IO(JD Multi-terminal Development Department)

License

FOSSA Status


[8]ページ先頭

©2009-2025 Movatter.jp