- babel-plugin-add-module-exports
- babel-plugin-transform-object-rest-spread // babel6
- @babel/plugin-proposal-object-rest-spread // babel7
- babel-plugin-transform-class-properties // babel6
- @babel/plugin-proposal-class-properties // babel7
- @babel/plugin-transform-regenerator // babel7
- babel-plugin-import
- @babel/plugin-transform-runtime
./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’
注意:
_
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
此插件转换静态类属性以及用属性初始值设定项语法声明的属性
class Bork {
//Property initializer syntax
instanceProperty = "bork";
boundFunction = () => {
return this.instanceProperty;
}
//Static class properties
static staticProperty = "babelIsCool";
static staticFunction = function() {
return Bork.staticProperty;
}
}
let myBork = new Bork;
//Property initializers are not on the prototype.
console.log(myBork.prototype.boundFunction); // > undefined
//Bound functions are bound to the class instance.
console.log(myBork.boundFunction.call(undefined)); // > "bork"
//Static function exists on the class.
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
外部化对助手和内置函数的引用,自动多填充代码而不污染全局