Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Babel: transpile into single output file

Tags:

babeljs

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...

like image 446
Andrey Bushman Avatar asked Oct 20 '25 14:10

Andrey Bushman


1 Answers

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
like image 97
loganfsmyth Avatar answered Oct 22 '25 04:10

loganfsmyth