【发布时间】:2016-08-24 00:35:18
【问题描述】:
我想要的是缩小 index.html 中的所有 js,然后删除所有 console.logs
我尝试了两种选择:
我尝试了合并,但只执行了 uglify
// Command: gulp useref
gulp.task('useref', function(){
var _uglify = gulp.src('app/index.html') // .src is the function that is very similar to locating or searching on that file or folder
.pipe(useref())
// Minifies only if it's a Javascript file
.pipe(gulpIf('*.js', uglify()))
// Minifies only if it's a CSS file
.pipe(gulpIf('*.css', cssnano()))
.pipe(gulp.dest('app/')) // .dest is the location where it will produce the output
// set to app/, so it will automatically change the index and there's no need to move files
var _strip_debug = gulp.src('app/assets/js/scripts.js')
.pipe(stripDebug())
.pipe(gulp.dest('app/assets/js'));
return merge(_uglify, _strip_debug);
});
我尝试返回两个,但只执行了 uglify:
gulp.task('useref', function(){
return gulp.src('app/index.html') // .src is the function that is very similar to locating or searching on that file or folder
.pipe(useref())
// Minifies only if it's a Javascript file
.pipe(gulpIf('*.js', uglify()))
// Minifies only if it's a CSS file
.pipe(gulpIf('*.css', cssnano()))
.pipe(gulp.dest('app/')) // .dest is the location where it will produce the output
// set to app/, so it will automatically change the index and there's no need to move files
return gulp.src('app/assets/js/scripts.js')
.pipe(stripDebug())
.pipe(gulp.dest('app/assets/js'));
});
【问题讨论】:
-
您的变量名称是
_uglify,但您将uglify传递给merge()?改变它会解决什么问题吗? -
我改了,错误消失了。但是,控制台日志不会被删除
标签: javascript gulp gulp-uglify