admin管理员组文章数量:1186099
I try to minify separate .js-files with gulp. Like:
file_one.js --> file_one.min.js
file_two.js --> file_two.min.js
It works the first time I execute gulp. But if I run it a second time it looks like this:
file_one.js
file_one.min.js
file_one.min.min.js
file_two.js
file_two.min.js
file_two.min.min.js
And it repeats that pattern every timme i execute gulp. How can I stop it from minify already minified js.
I use the following code:
gulp.task('scripts', function() {
return gulp.src('dest/*js')
.pipe(rename({ suffix: '.min' }))
.pipe(uglify())
.pipe(gulp.dest('dest'));
});
I try to minify separate .js-files with gulp. Like:
file_one.js --> file_one.min.js
file_two.js --> file_two.min.js
It works the first time I execute gulp. But if I run it a second time it looks like this:
file_one.js
file_one.min.js
file_one.min.min.js
file_two.js
file_two.min.js
file_two.min.min.js
And it repeats that pattern every timme i execute gulp. How can I stop it from minify already minified js.
I use the following code:
gulp.task('scripts', function() {
return gulp.src('dest/*js')
.pipe(rename({ suffix: '.min' }))
.pipe(uglify())
.pipe(gulp.dest('dest'));
});
Share
Improve this question
asked Jul 17, 2014 at 13:44
OscarOscar
1052 silver badges10 bronze badges
3 Answers
Reset to default 26You can put the minified files in a different directory, or you can exclude them in the gulp.src
like this:
gulp.task('scripts', function() {
return gulp.src(['dest/*.js', '!dest/*.min.js'])
.pipe(rename({ suffix: '.min' }))
.pipe(uglify())
.pipe(gulp.dest('dest'));
});
This is happening because you are saving the minified files in the same directory of your non minified files. The first part of your stream (gulp.src
) reads all files inside your dest
folder. Since you are saving your minified files to the very same folder, it is minifying them again on the second time it is run. the You have some options:
- Change the output folder to something else (for instance
gulp.dest('build')
) - Change
gulp.src
to match only the non-minified files
You are having problem with duplicate so you need to delete the destination file first to re-run the file. See Example:
//clean
gulp.task('clean', function(){
return del(['dist']);
});
//Default task
gulp.task('default',['clean'], function(){
gulp.start('usemin','imagemin','copy','views');
});
本文标签: javascriptgulp minifies already minified fileStack Overflow
版权声明:本文标题:javascript - gulp minifies already minified file - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738347163a2078285.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论