javascript - How can I run uglify then strip-debug in one task using gulp -


what want minify js in index.html remove console.logs

i tried 2 options:

i tried merge uglify executed

// command: gulp useref gulp.task('useref', function(){     var _uglify = gulp.src('app/index.html') // .src function similar locating or searching on file or folder     .pipe(useref())     // minifies if it's javascript file     .pipe(gulpif('*.js', uglify()))     // minifies if it's css file     .pipe(gulpif('*.css', cssnano()))     .pipe(gulp.dest('app/')) // .dest location produce output     // set app/, automatically change index , there's no need 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); }); 

i tried returning 2 uglify executed:

    gulp.task('useref', function(){         return gulp.src('app/index.html') // .src function similar locating or searching on file or folder         .pipe(useref())         // minifies if it's javascript file         .pipe(gulpif('*.js', uglify()))         // minifies if it's css file         .pipe(gulpif('*.css', cssnano()))         .pipe(gulp.dest('app/')) // .dest location produce output         // set app/, automatically change index , there's no need move files           return gulp.src('app/assets/js/scripts.js')         .pipe(stripdebug())         .pipe(gulp.dest('app/assets/js'));     }); 

i assume app/assets/js/scripts.js concatenated javascript file generated gulp-useref.

in case using merge-stream not work, because app/assets/js/scripts.js file might not yet exist when try gulp.src() it. instead add gulpif stage first stream:

gulp.task('useref', function(){    return gulp.src('app/index.html')      .pipe(useref())      .pipe(gulpif('*.js', stripdebug()))      .pipe(gulpif('*.js', uglify()))      .pipe(gulpif('*.css', cssnano()))      .pipe(gulp.dest('app/')) }); 

Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -