问题
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