在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):sindresorhus/gulp-filter开源软件地址(OpenSource Url):https://github.com/sindresorhus/gulp-filter开源编程语言(OpenSource Language):JavaScript 100.0%开源软件介绍(OpenSource Introduction):gulp-filter
Enables you to work on a subset of the original files by filtering them using glob patterns. When you're done and want all the original files back, you just use the Install
UsageFilter onlyYou may want to just filter the stream content: const gulp = require('gulp');
const uglify = require('gulp-uglify');
const filter = require('gulp-filter');
exports.default = () => {
// Create filter instance inside task function
const f = filter(['**', '!*src/vendor']);
return gulp.src('src/**/*.js')
// Filter a subset of the files
.pipe(f)
// Run them through a plugin
.pipe(uglify())
.pipe(gulp.dest('dist'));
}; Restoring filtered filesconst gulp = require('gulp');
const uglify = require('gulp-uglify');
const filter = require('gulp-filter');
exports.default = () => {
// Create filter instance inside task function
const f = filter(['**', '!*src/vendor'], {restore: true});
return gulp.src('src/**/*.js')
// Filter a subset of the files
.pipe(f)
// Run them through a plugin
.pipe(uglify())
// Bring back the previously filtered out files (optional)
.pipe(f.restore)
.pipe(gulp.dest('dist'));
}; Multiple filtersBy combining and restoring different filters you can process different sets of files with a single pipeline. const gulp = require('gulp');
const less = require('gulp-less');
const concat = require('gulp-concat');
const filter = require('gulp-filter');
exports.default = () => {
const jsFilter = filter('**/*.js', {restore: true});
const lessFilter = filter('**/*.less', {restore: true});
return gulp.src('assets/**')
.pipe(jsFilter)
.pipe(concat('bundle.js'))
.pipe(jsFilter.restore)
.pipe(lessFilter)
.pipe(less())
.pipe(lessFilter.restore)
.pipe(gulp.dest('out/'));
}; Restore as a file sourceYou can restore filtered files in a different place and use it as a standalone source of files (ReadableStream). Setting the const gulp = require('gulp');
const uglify = require('gulp-uglify');
const filter = require('gulp-filter');
exports.default = () => {
const f = filter(['**', '!*src/vendor'], {restore: true, passthrough: false});
const stream = gulp.src('src/**/*.js')
// Filter a subset of the files
.pipe(f)
// Run them through a plugin
.pipe(uglify())
.pipe(gulp.dest('dist'));
// Use filtered files as a gulp file source
f.restore.pipe(gulp.dest('vendor-dist'));
return stream;
}; APIfilter(pattern, options?)Returns a transform stream with a .restore property. patternType: Accepts a string/array with globbing patterns which are run through multimatch. If you supply a function, you'll get a filter(file => /unicorns/.test(file.path)); optionsType: Accepts Note: Set restoreType: Restore filtered files. passthroughType: When set to When the stream is a |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论