[英]Gulp task apply uglify if file in pipe is javascript
I want to check if the file in the pipe is .js
or not (it could be .map
, .html
, ...). 我想检查管道中的文件是否为
.js
(可能为.map
, .html
,...)。 And if so, uglifying it before copying it in the correct path. 如果是这样,请在将其复制到正确的路径之前对其进行丑化处理。
ʕ •́؈•̀) I've try something like this (which not working): ʕ•́؈•̀)我已经尝试过类似的方法(不起作用):
gulp.src(current + '/**/*', {base: current})
.pipe($.tap(function (file) {
if (path.extname(file.path) === '.js') {
return gulp.src(file.path)
.pipe($.uglify());
}
}))
.pipe(gulp.dest(destination + '/' + name));
But for now, the uglify seems to do nothing... 但是就目前而言,丑陋似乎无能为力...
Is anyone have a clue on how to do this ? 有人知道如何执行此操作吗? (╥﹏╥)
(╥﹏╥)
If you're open to using plugins there is one called gulp-filter that does what you're asking for. 如果您愿意使用插件,则可以使用一种名为gulp-filter的插件来满足您的要求。 https://www.npmjs.com/package/gulp-filter
https://www.npmjs.com/package/gulp-filter
It would probably look something like this 它可能看起来像这样
var gulp = require('gulp');
var gulpFilter = require('gulp-filter');
gulp.task('default', function () {
// create filter instance inside task function
var jsfilter = gulpFilter('**/*.js', {restore: true});
return gulp.src(current + '/**/*', {base: current})
// filter a subset of the files
.pipe(jsFilter)
// run them through a plugin
.pipe($.uglify())
// bring back the previously filtered out files (optional)
.pipe(jsFilter.restore)
.pipe(gulp.dest(destination + '/' + name));
});
try using gulp-filter 尝试使用gulp-filter
something like 就像是
var filter = require('gulp-filter');
var jsFilter = filter('**/*.js');
gulp.src('*/*')
.pipe(jsFilter)
.pipe(uglify)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.