I've been looking around for some .babelrc
option to remove comments from the transpiled code, but I haven't had any luck. I tried this:
{ "comments": false }
as well as
{ "options": { "comments": false } }
and neither works. I'm out of ideas, and I was unable to find any decent documentation anywhere.
You can also check the version of babel-cli by finding the babel-cli folder in node_modules and looking at the version property of the package. json that is at the base of that folder. If babel-cli was installed globally via -g flag of npm install , you could check the version by executing command babel --version .
Babel is a JavaScript compiler Babel is a toolchain that is mainly used to convert ECMAScript 2015+ code into a backwards compatible version of JavaScript in current and older browsers or environments.
The . babelrc file is your local configuration for your code in your project. Generally you would put it in the root of your application repo. It will affect all files that Babel processes that are in the same directory or in sibling directories of the . babelrc .
Using .babelrc
is always recommended:
{ comments: false }
If using babel-cli
, you can use the --no-comments
options to achieve the same behaviour.
The latest version of babel-cli
includes tests that check for this behaviour to be implemented correctly.
EDIT
It does look like a problem with babel CLI ignoring the comments in .babelrc
, a workaround is to use the --no-comments
option.
In your package.json
"build": "babel ./index.js --out-dir ./dist/index.js --no-comments"
To know all the options of babel-cli
./node_modules/.bin/babel -h
ORIGINAL
Where are you running babel from? Gulp?
Check that you have the .babelrc
file in the same or a parent directory of the files beign transpiled
From babeljs.io:
Babel will look for a .babelrc in the current directory of the file being transpiled. If one does not exist, it will travel up the directory tree until it finds either a .babelrc, or a package.json with a "babel": {} hash within.
I have a project with this structure:
The relevant task in gulpfile.js
gulp.task('babel', () => { return gulp.src('index.js') .pipe(babel({ presets: ['es2015'] })) .pipe(gulp.dest('./dist/')); });
Contents of .babelrc
{ "comments": false }
The comments are being succesfully removed.
Also check if you're not setting the comments
option to true in your gulpfile, for example.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With