[英]Gulp - remove comments from javascript files
I'm looking for a way to remove all comments from a javascript file using gulp. 我正在寻找一种方法来使用gulp从javascript文件中删除所有评论。
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 如果您只想删除评论,可以使用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 如果您还想缩小文件,请使用uglify
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.