Vin*_*nce 4 javascript node.js gulp gulp-filter
gulp-filter正在过滤所有内容.
我正在尝试使用gulp-filter从gulp-uglify中排除单个文件:
var uglify = require('gulp-uglify');
var filter = require('gulp-filter');
var paths = {
css: 'src/*.css',
html: 'src/*.html',
js: 'src/*.js'
};
gulp.task('js', function() {
// Create a filter for the ToC options file. We don't want to minify that.
var f = filter(['*', '!src/ToCOptions.js'], {"restore": true});
return gulp.src(paths.js)
.pipe(f)
.pipe(uglify())
.pipe(f.restore)
.pipe(gulp.dest('js'));
});
Run Code Online (Sandbox Code Playgroud)
我已经阅读了gulp-filter过滤掉所有文件,这似乎是同样的问题,但接受的答案对我不起作用.
我在过滤器上尝试了几种变体,包括:
var f = filter(['*', '!ToCOptions.js'], {"restore": true});var f = filter('!ToCOptions.js', {"restore": true});var f = filter('!src/ToCOptions.js', {"restore": true});var f = filter('src/ToCOptions.js', {"restore": true});var f = filter(['*', 'src/ToCOptions.js'], {"restore": true});var f = filter(['*', '!/src/ToCOptions.js'], {"restore": true});var f = filter(['*', '!/ToCOptions.js'], {"restore": true});我究竟做错了什么?
谢谢.
Vin*_*nce 10
显然,这是Github存储库中问题#55中解释的文档中的错误.
在我的情况下解决方案是这样的:
var f = filter(['**', '!src/ToCOptions.js'], {'restore': true});
Run Code Online (Sandbox Code Playgroud)
正如该问题的作者所解释的那样,单个星号仅匹配不在子目录中的文件.此任务的所有文件都在子目录中,因此第一个模式与任何内容都不匹配,第二个模式没有任何结果可以减去.
要理解**,我必须man bash在Linux系统上使用并搜索globstar,因为node-glob文档引用了Bash实现:
globstar
If set, the pattern ** used in a pathname expansion context will
match all files and zero or more directories and subdirectories. If the
pattern is followed by a /, only directories and subdirectories match.
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5152 次 |
| 最近记录: |