简体   繁体   English

如何使用 Gulp 对 uglify js 进行 gzip 压缩而不在 dist 文件夹中生成两个文件

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

I'm new using Gulp.我是使用 Gulp 的新手。

I'm wondering how can I concat, uglify and gzip all the js files from a static website using Gulp.我想知道如何使用 Gulp 对静态网站中的所有 js 文件进行连接、丑化和 gzip。

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我有一个这样的任务,但我只想在 dist 文件夹中包含 .gz 文件而不是组合的.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.就我而言,问题是由于 gulp-useref 使用不当造成的,因为在构建过程结束时生成了文件。 Probably noob problem, but hopefully can help anyone.可能是菜鸟问题,但希望可以帮助任何人。

Thanks in advance...提前致谢...

This should work.这应该有效。 Just store the .min file in a temp folder.只需将 .min 文件存储在临时文件夹中。 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.最终文件将是 build/js 中唯一的“combined.min.js.gz”。 If you don't like that name you could rename it with gulp-rename .如果你不喜欢这个名字,你可以用gulp-rename 重命名它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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