# ykit-config-react

> 编译 ES6+ react 插件

Latest version **2.3.2** (published 2018-01-29) · ISC license · 0 weekly downloads

## Install

```sh
npm install ykit-config-react
pnpm add ykit-config-react
yarn add ykit-config-react
bun add ykit-config-react
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.3.2 |
| Published | 2018-01-29 |
| First published | 2017-02-17 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 6 |
| Known vulnerabilities | 0 (+8 in 1 direct dependencies) |
| Install scripts | no |
| Maintainers | ymfe |

## Links

- npm: https://www.npmjs.com/package/ykit-config-react
- Repository: git@gitlab.corp.qunar.com:mfe/ykit-config-react
- npm.io page: https://npm.io/package/ykit-config-react

## Dependencies (6)

- [extend](https://npm.io/package/extend.md) ^3.0.0
- [fs-extra](https://npm.io/package/fs-extra.md) ^4.0.1
- [simple-git](https://npm.io/package/simple-git.md) ^1.77.0
- [es3ify-loader](https://npm.io/package/es3ify-loader.md) ^0.2.0
- [ykit-config-es6](https://npm.io/package/ykit-config-es6.md) ^3.2.1
- [babel-preset-react](https://npm.io/package/babel-preset-react.md) ^6.24.1

## Recent versions

- 2.3.2 (latest) — 2018-01-29
- 4.0.0-beta.2 (beta) — 2018-05-28
- 0.2.5-rc0 (rc) — 2017-04-05
- 4.0.0-beta.1 — 2018-05-22
- 4.0.0-beta.0 — 2018-05-17
- 2.3.1 — 2018-01-29
- 2.3.0 — 2018-01-16
- 2.2.3 — 2018-01-10
- 2.2.2 — 2018-01-10
- 2.2.1 — 2018-01-10
- 2.2.0 — 2018-01-10
- 2.1.0 — 2017-11-13
- 2.0.2 — 2017-11-07
- 2.0.1 — 2017-10-09
- 2.0.0 — 2017-09-28
- … 28 more at https://npm.io/package/ykit-config-react/versions

## README

# ykit-config-react

<b class="ykit-tip">
该插件已内置 ykit-config-es6，不需要单独引入。
</b>

## Features

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

## Usage

如果是新项目，在一个空的目录下执行：

```shell
$ ykit init react
```

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

如果是已有项目，在项目中执行：

```
$ npm install ykit-config-react --save
```

然后编辑 `ykit.js` 引入插件：

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

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

```javascript
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 头部，加入如下一行代码：

```javasciprt
import 'babel-polyfill';
```

<b class="ykit-tip">
babel-polyfill 会增大 js 体积（压缩后 80k 左右），请根据项目需求选择是否引入。
</b>

## 兼容 ie8

如果需要支持 ie8，则要指定 ie8 选项：

```javascript
module.exports = {
    plugins: [{
        name: 'react',
        options: {
            ie8: true
        }
    }]
    // ...
};
```

<b class="ykit-tip">
react 和 react-dom 从 15 版本开始已经不支持 ie8，请确保项目中安装 react@0.14.8 以及 react-dom@0.14.8 版本。
</b>

## 如何更改配置？

该插件支持更改 babel-loader 的 `test`、`exclude`、`query` 配置项：

```javascript
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

---
_Source: https://npm.io/package/ykit-config-react · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
