ykit-config-react
编译 ES6+ react 插件
Last updated 8 years ago by ymfe .
ISC · Repository · Original npm · Tarball · package.json
$ cnpm install ykit-config-react 
SYNC missed versions from official npm registry.

ykit-config-react

该插件已内置 ykit-config-es6,不需要单独引入。

Features

  • 编译 ES6+, JSX 代码(兼容至 IE8)
  • 通过 happypack 提升编译速度
  • 设置 react 环境变量
  • 初始脚手架

Usage

如果是新项目,在一个空的目录下执行:

$ ykit init react

会在当前目录下生成一个初始工程。

如果是已有项目,在项目中执行:

$ npm install ykit-config-react --save

然后编辑 ykit.js 引入插件:

module.exports = {
    plugins: ['react']
    // ...
};

或者如果需要添加选项,也可以采用传入对象的方式:

module.exports = {
    plugins: [{
        name: 'react',
        options: {
            // 插件选项
        }
    }]
    // ...
};

babel-polyfill

babel-polyfill 默认是没有引入的,需要根据项目需求手动引入。

功能

babel 默认只转换新的 JavaScript 句法(syntax),而不转换新的API,比如 Iterator、Generator、Set、Maps、Proxy、Reflect、Symbol、Promise 等全局对象,以及一些定义在全局对象上的方法(比如 Object.assign )都不会转码。如果需要这些 API 则要手动引入 babel-polyfill。

引入

引入 babel-polyfill 需要在入口 js 头部,加入如下一行代码:

import 'babel-polyfill';
babel-polyfill 会增大 js 体积(压缩后 80k 左右),请根据项目需求选择是否引入。

兼容 ie8

如果需要支持 ie8,则要指定 ie8 选项:

module.exports = {
    plugins: [{
        name: 'react',
        options: {
            ie8: true
        }
    }]
    // ...
};
react 和 react-dom 从 15 版本开始已经不支持 ie8,请确保项目中安装 react@0.14.8 以及 react-dom@0.14.8 版本。

如何更改配置?

该插件支持更改 babel-loader 的 testexcludequery 配置项:

module.exports = {
    plugins: [
        'qunar', {
            // 通过对象的方式引入插件,可以传入 options
            name: 'react',
            options: {
                // 更改 es6 配置
                test: /\.(js)$/, // 默认是 /\.(js|jsx)$/
                exclude: /node_modules\/(?!(MY_UI)\/).*/, // 默认是 /node_modules/
                modifyQuery: function(defaultQuery) { // 可查看和编辑 defaultQuery
                    defaultQuery.presets.push('my_preset');
                    defaultQuery.plugins.push('my_plugin');
                    return defaultQuery;
                }
            }
        }
    ],
    config: {
        // ...
    }
};

示例

查看:https://github.com/roscoe054/ykit-starter-react

Current Tags

  • 4.0.0-beta.2                                ...           beta (8 years ago)
  • 2.3.2                                ...           latest (8 years ago)
  • 0.2.5-rc0                                ...           rc (9 years ago)

43 Versions

  • 4.0.0-beta.2                                ...           8 years ago
  • 4.0.0-beta.1                                ...           8 years ago
  • 4.0.0-beta.0                                ...           8 years ago
  • 2.3.2                                ...           8 years ago
  • 2.3.1                                ...           8 years ago
  • 2.3.0                                ...           8 years ago
  • 2.2.3                                ...           8 years ago
  • 2.2.2                                ...           8 years ago
  • 2.2.1                                ...           8 years ago
  • 2.2.0                                ...           8 years ago
  • 2.1.0                                ...           8 years ago
  • 2.0.2                                ...           8 years ago
  • 2.0.1                                ...           9 years ago
  • 2.0.0                                ...           9 years ago
  • 1.2.3                                ...           9 years ago
  • 1.2.2                                ...           9 years ago
  • 1.2.1                                ...           9 years ago
  • 1.2.0                                ...           9 years ago
  • 1.1.0                                ...           9 years ago
  • 1.0.1                                ...           9 years ago
  • 1.0.0                                ...           9 years ago
  • 0.4.4                                ...           9 years ago
  • 0.4.3                                ...           9 years ago
  • 0.4.2                                ...           9 years ago
  • 0.4.1                                ...           9 years ago
  • 0.4.0                                ...           9 years ago
  • 0.3.2                                ...           9 years ago
  • 0.3.1                                ...           9 years ago
  • 0.3.0                                ...           9 years ago
  • 0.2.8                                ...           9 years ago
  • 0.2.7                                ...           9 years ago
  • 0.2.6                                ...           9 years ago
  • 0.2.5                                ...           9 years ago
  • 0.2.5-rc0                                ...           9 years ago
  • 0.2.4                                ...           9 years ago
  • 0.2.3                                ...           9 years ago
  • 0.2.2                                ...           9 years ago
  • 0.2.1                                ...           9 years ago
  • 0.2.0                                ...           9 years ago
  • 0.1.2                                ...           9 years ago
  • 0.1.1                                ...           9 years ago
  • 0.1.0                                ...           9 years ago
  • 0.0.1                                ...           9 years ago
Maintainers (1)
Downloads
Today 0
This Week 2
This Month 3
Last Day 1
Last Week 1
Last Month 6
Dependencies (6)
Dev Dependencies (0)
None
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |