在自己的目录下新建一个babel-test/目录
进入这个目录
1. 安装babel命令和转换库:
     npm install babel-cli
     npm install babel-preset-es2015
 
2. 在当前目录下新建文件夹: .babelrc
在文件夹中写入:
{
  "presets": ["./babel-preset-es2015"]
}
 
3. 新建一个文件example.es6,内容如下:
import $ from 'jquery'
 
export class MyClass {
    constructor(name = 'nobody') {
        this.name = name;
    }
    getMyName() {
        return this.name;
    }
}
 
4. 安装缺少的相关库
npm install ansi-regex ansi-styles escape-string-regexp has-ansi left-pad number-is-nan strip-ansi supports-color line-numbers
执行代码:
babel example.es6 -o example.js
如果还报错提示缺少模块:xxx-xxx
则安装它
npm install xxx-xxx
 
5. 大功告成
然后,在当前目录下,通过babel命令将es6代码转换成es5的代码了!
文件转化示例:
babel example.es6 -o example.js
文件夹转化示例:
babel -d example-es5/ example-es6
 
2015.12.1 yaoel
我的联系方式:yaoel@outlook.com
 
参考:

相关文章:

  • 2021-11-20
  • 2022-12-23
  • 2021-06-19
  • 2022-01-21
  • 2021-08-11
  • 2021-06-28
猜你喜欢
  • 2022-01-30
  • 2022-12-23
  • 2021-10-18
  • 2021-07-10
  • 2022-02-15
  • 2022-01-20
相关资源
相似解决方案