{"id":13447288,"url":"https://github.com/sindresorhus/gulp-filter","last_synced_at":"2026-04-17T08:09:51.266Z","repository":{"id":13145488,"uuid":"15827909","full_name":"sindresorhus/gulp-filter","owner":"sindresorhus","description":"Filter files in a `vinyl` stream","archived":false,"fork":false,"pushed_at":"2025-01-24T06:31:11.000Z","size":72,"stargazers_count":314,"open_issues_count":3,"forks_count":35,"subscribers_count":10,"default_branch":"main","last_synced_at":"2025-04-13T03:59:13.370Z","etag":null,"topics":["filter","gulp-plugin","javascript","nodejs"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sindresorhus.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/security.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"sindresorhus","open_collective":"sindresorhus","buy_me_a_coffee":"sindresorhus","custom":"https://sindresorhus.com/donate"}},"created_at":"2014-01-11T18:18:51.000Z","updated_at":"2025-01-24T06:31:15.000Z","dependencies_parsed_at":"2025-02-01T05:00:43.522Z","dependency_job_id":"72c0a4c5-5fd5-4aca-82e7-470b1abf211a","html_url":"https://github.com/sindresorhus/gulp-filter","commit_stats":{"total_commits":87,"total_committers":15,"mean_commits":5.8,"dds":"0.25287356321839083","last_synced_commit":"365f2e34c1cafe3e2fd3fea20dfc6a183431f2cf"},"previous_names":[],"tags_count":27,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fgulp-filter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fgulp-filter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fgulp-filter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fgulp-filter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sindresorhus","download_url":"https://codeload.github.com/sindresorhus/gulp-filter/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248661706,"owners_count":21141450,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["filter","gulp-plugin","javascript","nodejs"],"created_at":"2024-07-31T05:01:13.010Z","updated_at":"2026-04-17T08:09:51.221Z","avatar_url":"https://github.com/sindresorhus.png","language":"JavaScript","readme":"# gulp-filter\n\n\u003e Filter files in a [`vinyl`](https://github.com/gulpjs/vinyl) stream\n\nEnables 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 `restore` stream.\n\n## Install\n\n```sh\nnpm install --save-dev gulp-filter\n```\n\n## Usage\n\n### Filter only\n\nYou may want to just filter the stream content:\n\n```js\nimport gulp from 'gulp';\nimport uglify from 'gulp-uglify';\nimport filter from 'gulp-filter';\n\nexport default () =\u003e {\n\t// Create filter instance inside task function\n\tconst f = filter(['**', '!*src/vendor']);\n\n\treturn gulp.src('src/**/*.js')\n\t\t// Filter a subset of the files\n\t\t.pipe(f)\n\t\t// Run them through a plugin\n\t\t.pipe(uglify())\n\t\t.pipe(gulp.dest('dist'));\n};\n```\n\n### Restoring filtered files\n\n```js\nimport gulp 'gulp';\nimport uglify 'gulp-uglify';\nimport filter 'gulp-filter';\n\nexport default () =\u003e {\n\t// Create filter instance inside task function\n\tconst f = filter(['**', '!*src/vendor'], {restore: true});\n\n\treturn gulp.src('src/**/*.js')\n\t\t// Filter a subset of the files\n\t\t.pipe(f)\n\t\t// Run them through a plugin\n\t\t.pipe(uglify())\n\t\t// Bring back the previously filtered out files (optional)\n\t\t.pipe(f.restore)\n\t\t.pipe(gulp.dest('dist'));\n};\n```\n\n### Multiple filters\n\nBy combining and restoring different filters you can process different sets of files with a single pipeline.\n\n```js\nimport gulp from 'gulp';\nimport less from 'gulp-less';\nimport concat from 'gulp-concat';\nimport filter from 'gulp-filter';\n\nexport default () =\u003e {\n\tconst jsFilter = filter('**/*.js', {restore: true});\n\tconst lessFilter = filter('**/*.less', {restore: true});\n\n\treturn gulp.src('assets/**')\n\t\t.pipe(jsFilter)\n\t\t.pipe(concat('bundle.js'))\n\t\t.pipe(jsFilter.restore)\n\t\t.pipe(lessFilter)\n\t\t.pipe(less())\n\t\t.pipe(lessFilter.restore)\n\t\t.pipe(gulp.dest('out/'));\n};\n```\n\n### Restore as a file source\n\nYou can restore filtered files in a different place and use it as a standalone source of files (ReadableStream). Setting the `passthrough` option to `false` allows you to do so.\n\n```js\nimport gulp 'gulp';\nimport uglify 'gulp-uglify';\nimport filter 'gulp-filter';\n\nexport default () =\u003e {\n\tconst f = filter(['**', '!*src/vendor'], {restore: true, passthrough: false});\n\n\tconst stream = gulp.src('src/**/*.js')\n\t\t// Filter a subset of the files\n\t\t.pipe(f)\n\t\t// Run them through a plugin\n\t\t.pipe(uglify())\n\t\t.pipe(gulp.dest('dist'));\n\n\t// Use filtered files as a gulp file source\n\tf.restore.pipe(gulp.dest('vendor-dist'));\n\n\treturn stream;\n};\n```\n\n## API\n\n### filter(pattern, options?)\n\nReturns a [transform stream](https://nodejs.org/api/stream.html#stream_class_stream_transform) with a [.restore](#optionsrestore) property.\n\n#### pattern\n\nType: `string | string[] | Function`\n\nAccepts a string/array with globbing patterns which are run through [multimatch](https://github.com/sindresorhus/multimatch).\n\nIf you supply a function, you'll get a [`vinyl` file object](https://github.com/wearefractal/vinyl#file) as the first argument and you're expected to return a boolean of whether to include the file:\n\n```js\nfilter(file =\u003e /unicorns/.test(file.path));\n```\n\n#### options\n\nType: `object`\n\nAccepts [`minimatch` options](https://github.com/isaacs/minimatch#options).\n\n*Note:* Set `dot: true` if you need to match files prefixed with a dot, for example, `.gitignore`.\n\n##### restore\n\nType: `boolean`\\\nDefault: `false`\n\nRestore filtered files.\n\n##### passthrough\n\nType: `boolean`\\\nDefault: `true`\n\nWhen set to `true`, filtered files are restored with a `stream.PassThrough`, otherwise, when set to `false`, filtered files are restored as a `stram.Readable`.\n\nWhen the stream is a `stream.Readable`, it ends by itself, but when it's `stream.PassThrough`, you are responsible of ending the stream.\n","funding_links":["https://github.com/sponsors/sindresorhus","https://opencollective.com/sindresorhus","https://buymeacoffee.com/sindresorhus","https://sindresorhus.com/donate"],"categories":["JavaScript","Plugins","插件"],"sub_categories":["Miscellaneous Plugins","其他插件"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Fgulp-filter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsindresorhus%2Fgulp-filter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Fgulp-filter/lists"}