Tool系列—Babel

1、简单介绍

     这些转换器 (更准确地说是源代码到源代码的编译器) 可以把你写的符合 ECMAScript 6 标准的代码完美地转换为 ECMAScript 5 标准的代码,并且可以确保良好地运行在所有主流 JavaScript 引擎中。

    Babel对 ES6 的支持程度比其它同类更高,而且 Babel 拥有完善的文档和一个很棒的    在线交互式编程环境

2、学习资料

=========

Babel官网

http://babeljs.io/docs/setup/

3、Babel介绍

    babel可以惊醒单独使用。

3.1、环境安装

npm install --global babel-cli

3.2、编译单独文件


Compile the file script.js and output to stdout.

$ babel script.js # output...

If you would like to output to a file you may use --out-file or -o.

$ babel script.js --out-file script-compiled.js

To compile a file every time that you change it, use the --watch or -w option:

$ babel script.js --watch --out-file script-compiled.js

3.3、Compile with Source Maps(不太会用,回头再说)

If you would then like to add a source map file you can use --source-maps or -s. Learn more about source maps.

$ babel script.js --out-file script-compiled.js --source-maps

If you would rather have inline source maps, you may use --source-maps inline.

$ babel script.js --out-file script-compiled.js --source-maps inline

3.4、编译文件夹


Compile the entire src directory and output it to the lib directory. You may use --out-dir or -d.

$ babel src --out-dir lib

Compile the entire src directory and output it to the one concatenated file.

$ babel src --out-file script-compiled.js

3.5、管道文件(Piping Files)(应用场景不太清楚)

Pipe a file in via stdin and output it to script-compiled.js

$ babel --out-file script-compiled.js < script.js

4、Babel-node介绍(应用场景不太清楚)

    就是和node的一样就是可以直接在cmd中敲命令,运行代码

    babel comes with a second CLI which works exactly the same as Node.js's CLI, only it will compile ES6 code before running it.

4.1、使用


    启动Launch a REPL (Read-Eval-Print-Loop).

$ babel-node

    评估Evaluate code.

$ babel-node -e "class Test { }"

    编译Compile and run test.js.

$ babel-node test

4.2、应用


$ babel-node [options] [ -e script | script.js ] [arguments]

When arguments for user script have names conflicting with node  options, double dash placed before script name can be used to resolve  ambiguities

$ babel-node --debug --presets es2015 -- script.js --debug

4.3、配置

Option

Default

Description

-e, --eval [script]

Evaluate script

-p, --print

Evaluate script and print result

-i, --ignore [regex]

node_modules

Ignore all files that match this regex when using the require hook

-x, --extensions

".js",".jsx",".es6",".es"

List of extensions to hook into

presets

[]

List of presets (a set of plugins) to load and use.

plugins

[]

List of plugins to load and use.

5、配置文件

=========

    创建 .babelrc配置文件,这里面可以放插件

    你应该准确的告诉babel应该编译成什么东西

Great! You've configured Babel but you haven't made it actually do anything. Create a .babelrc config in your project root and enable some plugins.

Note

Pre-6.x, Babel enabled certain transformations by default. However, Babel 6.x does not ship with any transformations enabled. You need to explicitly tell it what transformations to run. The simplest way to do this is by using a preset, such as the ES2015 Preset.

6、预设(Presets)

    babel已经为大家准备了一些预设插件,用来处理一些操作,比如es2015和react

7、Gulp中使用babel

=================

https://github.com/babel/gulp-babel

8、webpack中使用babel

https://github.com/babel/babel-loader

9、其他

①****我们如果不会用可以去github中搜索 gulp  babel的快速开始文档,需要哪些知识点整合的就输入哪些关键字

②****我们在搜索一些学习的博客和文章的时候,先看发表日期,这些开源项目现在更新的很快,有些东西的用法都改变了,最好跟着官网走

②  http://blog.csdn.net/yczz/article/category/354754  这哥们的ria可以看一下

点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

皕杰报表之UUID

​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

一篇文章带你了解JavaScript日期

日期对象允许您使用日期(年、月、日、小时、分钟、秒和毫秒)。一、JavaScript的日期格式一个JavaScript日期可以写为一个字符串:ThuFeb02201909:59:51GMT0800(中国标准时间)或者是一个数字:1486000791164写数字的日期,指定的毫秒数自1970年1月1日00:00:00到现在。1\.显示日期使用