How to remove comments from submitted code using babel-cli

I was looking for some .babelrc option to remove comments from the passed code, but I had no luck. I tried this:

 { "comments": false } 

as well as

 { "options": { "comments": false } } 

and does not work. I have no ideas, and I could not find decent documentation anywhere.

+6
source share
1 answer

Recommended to use .babelrc :

 { comments: false } 

If you use babel-cli , you can use the --no-comments options to achieve the same behavior.

The latest version of babel-cli contains tests that verify the correct implementation of this behavior .


EDIT

This seems like a problem with the CLI for Babel, ignoring 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 find out all the parameters of babel-cli

 ./node_modules/.bin/babel -h 

ORIGINAL

Where are you running from with Babel? Gulp?

Make sure you have a .babelrc file in the same or parent directory of files hidden in the file

From babeljs.io :

Babel will search for .babelrc in the current directory of the file being transported. If it does not exist, it will be a directory tree until it finds either .babelrc or package.json with "babel": {} hash inside.

I have a project with this structure:

  • distance
    • index.js
  • .babelrc
  • index.js
  • gulpfile.js
  • node_modules
    • ...

Corresponding task in gulpfile.js

 gulp.task('babel', () => { return gulp.src('index.js') .pipe(babel({ presets: ['es2015'] })) .pipe(gulp.dest('./dist/')); }); 

Content .babelrc

 { "comments": false } 

Comments are deleted successfully.

Also check if the comments true parameter is configured in your gulpfile, for example.

+9
source

All Articles