• Stars
    star
    5,421
  • Rank 7,589 (Top 0.2 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 7 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

Build Status License Coverage Status Downloads Build Status Sauce 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 in JD.com home page and TOPLIFE.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 using Lerna. That means that we actually publish several packages to npm from the same codebase, including:

Package Description
nervjs The core of Nerv
nerv-redux Nerv binding for Redux
nerv-devtools Provides support for React's Dev Tools for Nerv
nerv-server Support for server side rendering
nerv-test-utils Suite of utilities for testing Nerv applications
nerv-utils Internal Helpers functions for Nerv
nerv-shared Internal shared functions for Nerv
nerv-create-class The legacy createClass API for Nerv

Getting Started

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

Install

Of course we recommend that you use Nerv with Webpack and Babel.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:

import Nerv from 'nervjs'
class HelloMessage extends Nerv.Component {
  render() {
    return <div>Hello {this.props.name}</div>
  }
}

Nerv.render(
  <HelloMessage name="Nerv" />,
  document.getElementById('app')
)

Named:

import { Component, render } from 'nervjs'
class HelloMessage extends Component {
  render() {
    return <div>Hello {this.props.name}</div>
  }
}

render(
  <HelloMessage name="Nerv" />,
  document.getElementById('app')
)

☝️ For more information please move to the official development document

Examples

Switching to Nerv from React

Switching to Nerv from React is easy as adding alias nervjs for react and react-dom. No changes in code needed.

Usage with Webpack

Add an alias in your webpack.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 your package.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, install es5-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 using babel:

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

Developer Tools

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

To enable the Nerv development tools you must install the nerv-devtools module and then require('nerv-devtools') before the initial Nerv.render().

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

nerv-devtools

Change Log

Acknowledgement

AOTU.IO(JD Multi-terminal Development Department)

License

FOSSA Status

More Repositories

1

taro

开放式跨端跨框架解决方案,支持使用 React/Vue/Nerv 等框架来开发微信/京东/百度/支付宝/字节跳动/ QQ 小程序/H5/React Native 等应用。 https://taro.zone/
TypeScript
35,513
star
2

taro-ui

一款基于 Taro 框架开发的多端 UI 组件库
TypeScript
4,537
star
3

awesome-taro

多端统一开发框架 Taro 优秀学习资源汇总
2,683
star
4

taro-zhihu-sample

a demo based on taro
JavaScript
342
star
5

taro-ui-demo

非 Taro UI 官网示例代码
JavaScript
285
star
6

tarojs-plugin-ssr

让 Taro H5 支持 Pre-rendering、SSR 和 ISR,极致的首屏速度🚀,利于 SEO🔍
TypeScript
229
star
7

taro-native-shell

Taro 原生 React Native 壳子
Java
196
star
8

taro-sample-weapp

与小程序原生融合的示例
JavaScript
159
star
9

taro-v2ex

使用 Taro 实现 V2EX 小程序
TypeScript
155
star
10

taro-v2ex-hooks

使用 Taro 和 React Hooks 构建 v2ex 小程序
TypeScript
139
star
11

taro-project-templates

Templates for `taro init`
JavaScript
81
star
12

taro-rfcs

为了重大特性更新和架构更改顺利推进的 RFC 流程机制
74
star
13

taro-ui-sample

基于 Taro 的多端 UI 库示范用例
JavaScript
68
star
14

taro-antd-mobile

Taro 兼容 Ant Design Mobile
SCSS
60
star
15

taro-todo

多端解决方案示例
JavaScript
56
star
16

nerv-webpack-boilerplate

A webpack boilerplate with Nervjs
JavaScript
52
star
17

taro-components-sample

taro components sample
JavaScript
52
star
18

TodoMVC

TodoMVC with Taro + Redux
JavaScript
43
star
19

taro3-vant-sample

Taro3 中使用 vant-weapp 的示例
JavaScript
42
star
20

taro-todomvc-hooks

用 Taro 和 React Hooks API 实现 TodoMVC
JavaScript
41
star
21

taro-vant

Taro 兼容 VantUI
Vue
40
star
22

taro-redux-sample

taro redux sample
JavaScript
37
star
23

taro-uilib-react

Taro UI 库 React 版本范例
JavaScript
34
star
24

at-ui-nerv

AT-UI for Nerv
TypeScript
31
star
25

taro-plugin-inject

Taro 小程序端平台中间层插件
TypeScript
31
star
26

taro-user-cases

使用 Taro 开发的案例
JavaScript
29
star
27

taro-plugin-mock

Taro 数据 Mock 插件
TypeScript
27
star
28

taro-plugin-platform-kwai

快手小程序平台插件
TypeScript
26
star
29

taro-plugin-platform-lark

飞书(Lark)小程序平台插件
TypeScript
20
star
30

taro-plugin-platform-weapp-qy

企业微信插件
TypeScript
20
star
31

taro-components-test

Taro 组件化方案测试
JavaScript
20
star
32

taro-weui

Taro 兼容 WEUI
SCSS
18
star
33

taro-docs

Taro 文档
MDX
18
star
34

taro-bot

A bot app for Taro
TypeScript
16
star
35

taro-plugin-platform-alipay-dd

钉钉小程序平台插件
TypeScript
16
star
36

taro-apis-sample

taro apis sample
JavaScript
11
star
37

taro-plugin-platform-xhs

小红书小程序平台插件
TypeScript
11
star
38

taro-blended

在原生小程序项目中使用 Taro
JavaScript
10
star
39

taro-flexbox

Taro 跨端的flexbox布局案例
TypeScript
10
star
40

nerv-website

The landing page of Nerv
JavaScript
10
star
41

nerv-redux-todomvc

TodoMVC example using Nerv and Redux
TypeScript
9
star
42

parse-css-to-stylesheet

css转stylesheet插件,适用于鸿蒙、RN
Rust
8
star
43

taro-test-utils

多端单测工具
TypeScript
8
star
44

taro-component-website

Taro 基础组件库文档
CSS
6
star
45

taro-ui-theme-preview

Taro UI 自定义主题生成器
JavaScript
5
star
46

taro-calendar

一款基于 Taro 框架开发的多端 日历组件
TypeScript
5
star
47

taro-doctor

taro doctor based on NAPI-RS
Rust
4
star
48

nerv-server

Server-side rendering for Nerv.js
TypeScript
4
star
49

postcss-pxtransform

JavaScript
3
star
50

taro-plugin-indie

Taro 单独分包运行插件
TypeScript
3
star
51

taro-website

The landing page of Taro
JavaScript
3
star
52

taro-benchmark

Benchmark of Taro, weapp and jdapp.
JavaScript
3
star
53

taro-todos-pinia

Taro3 + Vue3 + pinia
Vue
2
star
54

taro-plugin-platform-alipay-iot

支付宝 IOT 端小程序平台插件
TypeScript
2
star
55

taro-plugin-shared-runtime

微信小程序多分包共享Taro运行时插件
TypeScript
2
star
56

nerv-test-utils

Mock react-test-utils used for Nerv.js
TypeScript
2
star
57

taro-issue-helper

https://nervjs.github.io/taro-issue-helper/
Vue
1
star
58

taro-ui-bot

A bot app for taro-ui
TypeScript
1
star
59

taro-plugin-migrate

快速升级迁移插件
TypeScript
1
star