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:
- dist
- index.js
- .babelrc
- index.js
- gulpfile.js
- node_modules
- …
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.