基本配置书写 { "PResets":[], "plugins":[] }
{ "plugins": ["transform-runtime", options] } Babel支持自定义的预设(presets)或插件(plugins)。 如果你的插件在npm上, 可以直接采用这种方式“plugins”: [“babel-plugin-myPlugin”] 等价方式“plugins”: [“myPlugin”]。此外,你还可以采用本地的相对路径引入插件,比如“plugins”:[“./node_modules/Myplugin”]。 presets同理。 babel官网
balel a.js 直接输出转换后的js babel a.js --out-file b.js babel a.js -o b.js 输出到b.js babel dir1 --out-dir dir2 babel dir1 -d dir2 路径下输出 babel src -d lib -s -s 参数生成source map文件
babel-cli带一个babel-node 支持类似node 可以直接运行ES6
babel-register模块改写require命令,为它加上一个钩子。此后,每当使用require加载.js、.jsx、.es和.es6后缀名的文件,就会先用Babel进行转码,在js…文件中引入; require("babel-register"); 就不需要手动对index.js转码了
新闻热点
疑难解答