Gulp - remove comments from javascript files

I am looking for a way to remove all comments from a javascript file using gulp.

For example, I have the following code:

/*** * Comment 1 - This is my javascript header * @desc comment header to be removed * @params req, res */ (function() { var helloworld = 'Hello World'; // Comment 2 - this is variable /* Comment 3 - this is the printing */ console.log(helloworld); })() 

And my expected result:

 (function() { var helloworld = 'Hello World'; console.log(helloworld); })(); 
+6
source share
1 answer

If you want to remove only comments, you can use gulp-strip-comments

 var gulp = require('gulp'); var strip = require('gulp-strip-comments'); gulp.task('default', function () { return gulp.src('template.js') .pipe(strip()) .pipe(gulp.dest('dist')); }); 

If you want to also reduce the file, use uglify

+9
source

Source: https://habr.com/ru/post/983826/


All Articles