I'm 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 is:
(function() {
var helloworld = 'Hello World';
console.log(helloworld);
})();
If you want remove just 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 also minify a file, use uglify
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