Gulp-从javascript文件中删除注释

Gulp-从javascript文件中删除注释,javascript,gulp,Javascript,Gulp,我正在寻找一种使用gulp从javascript文件中删除所有注释的方法 例如,我有以下代码: /*** * 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 /* C

我正在寻找一种使用gulp从javascript文件中删除所有注释的方法

例如,我有以下代码:

/***
 * 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);
})()
我的预期结果是:

(function() {
    var helloworld = 'Hello World';
    console.log(helloworld);
})();

如果只想删除注释,可以使用


如果您还想缩小文件,请使用

您所说的“仅注释”是什么意思?它的输出是否可以通过管道传输到uglify/minify?愚蠢的我,我在uglify配置上保留了注释以保存一些注释。谢谢
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'));
});