> For the complete documentation index, see [llms.txt](https://azr.gitbook.io/webpack/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://azr.gitbook.io/webpack/shi-zhan/es6.md).

# ES6

### babel

安装

```javascript
$ npm i  -D babel-preset-es2015 babel-preset-stage-2 babel-preset-stage-1 babel-preset-stage-0
```

新建文件`.babelrc`

```javascript
{
  "plugins": [
    [
      "transform-runtime",
      {
        "polyfill": false
      }
    ]
   ],
  "presets": [
    [
      "es2015",
      {
        "modules": false
      }
    ],
    "stage-2",
  ]
}
```

### Plugins

安装

```javascript
$ npm i babel-plugin-transform-runtime  -D
```

### 配置 <a href="#jie-ru-babel" id="jie-ru-babel"></a>

安装

```javascript
$ npm i babel-core babel-loader@7  babel-preset-env -D
```

```javascript
module.exports = {
  module: {
    rules: [
      {
        test: /\.js$/,
        use: ['babel-loader'],
      },
    ]
  },
  // 输出 source-map 方便直接调试 ES6 源码
  devtool: 'source-map'
};
```

### WARNING

```javascript
WARNING in ./node_modules/sockjs-client/dist/sockjs.js 1242:64-72
"export 'default' (imported as '_typeof2') was not found in 'babel-runtime/helpers/typeof'
 @ (webpack)-dev-server/client/socket.js
 @ (webpack)-dev-server/client?http://localhost:7777
 @ multi (webpack)-dev-server/client?http://localhost:7777 ./entry.js

WARNING in ./node_modules/sockjs-client/dist/sockjs.js 4:54-62
"export 'default' (imported as '_typeof2') was not found in 'babel-runtime/helpers/typeof'
 @ (webpack)-dev-server/client/socket.js
 @ (webpack)-dev-server/client?http://localhost:7777
 @ multi (webpack)-dev-server/client?http://localhost:7777 ./entry.js
```

#### 😢 记得要排除`node_modules`文件夹。

```javascript
module.exports = {
  module: {
    rules: [
      {
        test: /\.js$/,
        use: ['babel-loader'],
        exclude: /node_modules/
      },
    ]
  }
};
```

�
