ES6 之 命令行环境运行

  • Babel 提供babel-cli工具,用于命令行转码。

    
        npm install --global babel-cli
    
        npm install --save babel-preset-es2015
    
    
  • 当前目录下新建配置文件.babelrc

    
       {
         "presets": ['es2015']
       }
    
    
  • Babel基本用法如下

       # babel自带babel-node命令
       $ babel-node
       >
       > console.log([1,2,3].map(x => x * x));
         [1,4,9]
       >
    
    
       # 转码结果输出标准 es6 -> es5
       $ babel doslink.js
       "use strict";
    
       console.log([1, 2, 3].map(function (x) {
         return x * x;
       }));
    
    
       # 转码结果写入一个文件
       # --out-file 或 -o 参数指定输出文件
       $ babel doslink.js --out-file compiled.js
       # 或者
       $ babel doslink.js -o compiled.js
    
    
       # 整个目录转码
       # --out-dir 或 -d 参数指定输出目录
       $ babel es6 --out-dir build-dir
       # 或者
       $ babel es6 -d build-dir
    
    
       # -s 参数生成source map文件
       $ babel es6 -d build-dir -s
    

转载于:https://my.oschina.net/u/3041966/blog/1609158

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值