Front-end development thinking
sansazhang / blog Goto Github PK
View Code? Open in Web Editor NEWFront-end development thinking
Front-end development thinking
babel6.x做了模块化,把所有转换器都被分离出去以插件的形式存在,需要单独安装插件包. 意味着默认情况下babel不会对文件做任何转换.你需要:
npm install babel-plugin-transform-es2015-arrow-functions
{
"plugins": ["transform-es2015-arrow-functions"]
}
浏览babel6的所有插件
不用担心你需要在配置文件中指定和维护大量的转换器信息,你可以在babel6中预设插件,可以将一组类似的插件打包使用.
安装预设插件
npm install --save-dev babel-preset-es2015
.babelrc
{
“presets”: [“es2015”]
}
这样可以使用ES2015的所有语法
浏览babel6的所有预设插件
npm install --save-dev fis-parse-babel-6.x
parser: fis.plugin('babel-6.x', {
sourceMaps: true,
})
.babelrc
{
"presets": ["es2015","react","stage-0"],
"plugins": ["transform-decorators-legacy"],
}
本以为已经完事了,结果fis release 不能正确编译:
不能识别es7装饰器语法,找不到transform-decorators-legacy
插件;在fis-parse-babel-6.x
项目的issues下找到解决方案,删除插件fis-parse-babel-6.x
里的 conf.filename = file.subpath;
即可正常编译.
module
源码:
let demo = {};
demo.foo=function(){};
export default demo;
babel5编译的结果:
define("module",function(require,exports,module){
"use strict";
Object.defineProperty(t,"__esModule",{value:!0});
var demo={};
demo.foo=function(){};
exports["default"]=demo;
module.exports=exports["default"];
});
babel6编译的结果:
define("module",function(require,exports){
"use strict";
Object.defineProperty(t,"__esModule",{value:!0});
var demo={};
demo.foo=function(){};
exports.default=demo;
});
babel6的结果少了一句 module.exports=exports["default"]
不再将结果放置在module.exports
中,因此export default
模块的引入使用require
必须指明.default
; 使用import
不能使用解构形式引入:
var a = require('module'); // ×
var a = require('module').default; // √
a.foo();
or
import {a} from 'module'; // ×
import a from 'module'; // √
a.foo();
可以使用插件babel-plugin-add-module-exports来兼容不正确的代码.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.