We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
有个疑问,以编程的方式来使用 Babel,如果某些代码需要调用Babel的API进行转码,就要使用babel-core模块。为啥转换的只是{ code, map, ast },不是应该转换成es5代码啥的,那这个模块在实际项目中到底怎么用的?求告知
The text was updated successfully, but these errors were encountered:
@thelongmarch babel-core 是 babel 语法分析的核心库,的确是会如你所说的,指定 plugins 执行后得到的 result 是一个对象,它包含很多内容,比如你的 options (也就是 core 执行传给的参数),ast 是抽象语法树,可以理解为是给解析器看的,然后 code 就是编译后的代码了,你可以打出来看看~ 但是像我们平常用,很少直接用到 babel-core,通常是用 babel-cli 或者是 babel-loader。babel-cli 就是执行 babel 的时候调用的,比如 babel a.js --out-file b.js,就是把 a 文件通过 babel 编译得到 b,而 cli 内部是依赖 babel-core 处理的,只是变成了命令行工具方便我们使用。而 babel-loader 就是结合 webpack 使用的,实现也是依赖 babel-core。core 在项目中,基本不会用到,因为已经有封装好的工具了,但是你仍然可以自己去通过写脚本的形式做一些事,通常是工具类的。比如通过 transformFileSync 编译得到 code,写到新的文件里去,或者实现一个前端项目,可以上传文件,让用户配置参数,做 babel 的编译处理,然后可以把编译好的文件再反给用户下载。
babel a.js --out-file b.js
Sorry, something went wrong.
谢谢了,还是你理解的透彻,我一直纳闷为啥很少看到项目中使用,core确实是babel的核心,佩服!!!
No branches or pull requests
有个疑问,以编程的方式来使用 Babel,如果某些代码需要调用Babel的API进行转码,就要使用babel-core模块。为啥转换的只是{ code, map, ast },不是应该转换成es5代码啥的,那这个模块在实际项目中到底怎么用的?求告知
The text was updated successfully, but these errors were encountered: