Babel:转换成单个输出文件 [英] Babel: transpile into single output file

查看:49
本文介绍了Babel:转换成单个输出文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Babel 7.2.0

Babel 7.2.0

我需要转换我的JS文件并将它们组合成单个结果文件.这是我的尝试:

I need to transpile my JS-files and combine they into single result file. This is my attempt:

npx babel --source-root src/index.js --out-file lib/result.js --minified --presets @ babel/preset-env

但是我得到了错误:

babel:
stdin编译需要-f/-filename [filename]或--no-babelrc

babel:
stdin compilation requires either -f/--filename [filename] or --no-babelrc

我尝试了 -f -no-babelrc ,但这对我没有帮助...

I tried -f and --no-babelrc but it doesn't help me...

推荐答案

您当前的命令从不告诉Babel要编译哪个文件,因此希望文件内容来自stdin.由于stdin还具有其他要求,因此会出现该错误.真正的问题是,您似乎实际上并不想使用stdin.如果我们看看您的命令

Your current command never tells Babel what file to compile, so it is expecting the file content to come from stdin. Since stdin also has additional requirements, you get that error. The real issue though is, you don't actually seem to want to use stdin. If we look at your command

babel --source-root src/index.js --out-file lib/result.js

核心问题是-source-root 需要一个值,因此您基本上已经完成了

the core issue is that --source-root takes a value, so you've essentially done

babel.transformFile({
  filename: ????
  sourceRoot: "src/index.js"
});

因为命令中没有任何内容实际上给出了文件名.大概您打算将 src/index.js 用作文件名,因此您可能只是在滥用 sourceRoot ?我的猜测是您想要

because nothing in your command actually gives the filename. Presumably you intend src/index.js to be the filename, so you may just be misusing sourceRoot? My guess would be that you want

npx babel src/index.js --out-file lib/result.js --minified --presets @babel/preset-env

这篇关于Babel:转换成单个输出文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆