简体   繁体   中英

How can I gzip a uglify js with Gulp without generating two file in dist folder

I'm new using Gulp.

I'm wondering how can I concat, uglify and gzip all the js files from a static website using Gulp.

I have a task like this that works but I would like to only include in the dist folder the .gz file and not the combined.js

gulp.task("concat-js", function () {
return gulp.src("./src/js/*.js")
    .pipe(concat("combined.min.js"))
    .pipe(uglify())
    .pipe(gzip())
    .pipe(gulp.dest("./build/js"));
});

UPDATE

I encourage you to read the comments. In my case, the problem has been caused by a bad use of gulp-useref, because was generating the file at the end of the build process. Probably noob problem, but hopefully can help anyone.

Thanks in advance...

This should work. Just store the .min file in a temp folder. You can delete that later if you want.

gulp.task("concat-js", function () {
  return gulp.src("./src/js/*.js")
   .pipe(concat("combined.min.js"))

   .pipe(gulp.dest('./temp'))

   .pipe(uglify())
   .pipe(gzip())
   .pipe(gulp.dest("./build/js"));
});

The final file would be "combined.min.js.gz" the only one in build/js. If you don't like that name you could rename it with gulp-rename .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM