./node_modules/.bin/babel src —out-dir lib > ~/output.txt

babel-plugin-add-module-exports

Babel@6 transforms the following file export default ‘foo’ into ‘use strict’;
Object.defineProperty(exports, “esModule”, {
value: true
});
exports.default = ‘foo’; Therefore, it is a need to use the ugly .default in node.js. require(‘./bundle.js’)
// { default: ‘foo’ }
require(‘./bundle.js’).default _// ‘foo’
注意:
image.png_
babel7禁止使用
—————————————————————————

babel-plugin-transform-object-rest-spread // babel6

let { x, y, z } = { x: 1, y: 2, a: 3, b: 4 };
console.log(x); // 1
console.log(y);
// 2
console.log(z); _// { a: 3, b: 4 }_

@babel/plugin-proposal-object-rest-spread // babel7

let { x, y, z } = { x: 1, y: 2, a: 3, b: 4 };
console.log(x); // 1
console.log(y);
// 2
console.log(z); _// { a: 3, b: 4 }_

babel-plugin-transform-class-properties // babel6

@babel/plugin-proposal-class-properties // babel7

此插件转换静态类属性以及用属性初始值设定项语法声明的属性

  1. class Bork {
  2. //Property initializer syntax
  3. instanceProperty = "bork";
  4. boundFunction = () => {
  5. return this.instanceProperty;
  6. }
  7. //Static class properties
  8. static staticProperty = "babelIsCool";
  9. static staticFunction = function() {
  10. return Bork.staticProperty;
  11. }
  12. }
  13. let myBork = new Bork;
  14. //Property initializers are not on the prototype.
  15. console.log(myBork.prototype.boundFunction); // > undefined
  16. //Bound functions are bound to the class instance.
  17. console.log(myBork.boundFunction.call(undefined)); // > "bork"
  18. //Static function exists on the class.
  19. console.log(Bork.staticFunction()); // > "babelIsCool"

@babel/plugin-transform-regenerator // babel7

将异步和生成器函数分解为状态机。

babel-plugin-import

{ "libraryName": "antd" }

import { Button } from ‘antd’;
ReactDOM.render(<Button>xxxx</Button>);

↓ ↓ ↓ ↓ ↓ ↓

var _button = require(‘antd/lib/button’);
ReactDOM.render(<_button>xxxx</_button>);

{ "libraryName": "antd", style: "css" }

import { Button } from ‘antd’;
ReactDOM.render(<Button>xxxx</Button>);

↓ ↓ ↓ ↓ ↓ ↓

var _button = require(‘antd/lib/button’);
require(‘antd/lib/button/style/css’);
ReactDOM.render(<_button>xxxx</_button>);

@babel/plugin-transform-runtime

外部化对助手和内置函数的引用,自动多填充代码而不污染全局