Babel: transpile into single output file

心不动则不痛 提交于 2021-01-28 01:56:34

问题


Babel 7.2.0

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

But I get the error:

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

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


回答1:


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

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

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

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


来源:https://stackoverflow.com/questions/53791435/babel-transpile-into-single-output-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!