{"id":13398058,"url":"https://github.com/sindresorhus/gulp-rev","last_synced_at":"2025-05-14T05:10:37.239Z","repository":{"id":12540559,"uuid":"15210616","full_name":"sindresorhus/gulp-rev","owner":"sindresorhus","description":"Static asset revisioning by appending content hash to filenames: `unicorn.css` → `unicorn-d41d8cd98f.css`","archived":false,"fork":false,"pushed_at":"2023-11-03T13:28:25.000Z","size":128,"stargazers_count":1543,"open_issues_count":16,"forks_count":212,"subscribers_count":28,"default_branch":"main","last_synced_at":"2025-05-05T14:09:19.989Z","etag":null,"topics":["gulp-plugin","hash","javascript","manifest","nodejs","rev"],"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":".github/contributing.md","funding":".github/funding.yml","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},"funding":{"github":"sindresorhus","open_collective":"sindresorhus","custom":"https://sindresorhus.com/donate"}},"created_at":"2013-12-15T20:56:05.000Z","updated_at":"2025-04-11T11:53:53.000Z","dependencies_parsed_at":"2024-02-16T11:08:29.676Z","dependency_job_id":"36d8c271-97d3-4b1e-8762-631fe0d2b0ac","html_url":"https://github.com/sindresorhus/gulp-rev","commit_stats":{"total_commits":134,"total_committers":39,"mean_commits":"3.4358974358974357","dds":0.4029850746268657,"last_synced_commit":"1e20ee1da01379dcf18f98ff4932da7cdcb38cd4"},"previous_names":[],"tags_count":31,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fgulp-rev","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fgulp-rev/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fgulp-rev/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fgulp-rev/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sindresorhus","download_url":"https://codeload.github.com/sindresorhus/gulp-rev/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252932277,"owners_count":21827268,"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":["gulp-plugin","hash","javascript","manifest","nodejs","rev"],"created_at":"2024-07-30T18:02:04.427Z","updated_at":"2025-05-14T05:10:37.212Z","avatar_url":"https://github.com/sindresorhus.png","language":"JavaScript","readme":"# gulp-rev\n\n\u003e Static asset revisioning by appending content hash to filenames\n\u003e `unicorn.css` → `unicorn-d41d8cd98f.css`\n\n**This project is feature complete. PRs adding new features will not be accepted.**\n\nMake sure to set the files to [never expire](http://developer.yahoo.com/performance/rules.html#expires) for this to have an effect.\n\n## Install\n\n```sh\nnpm install --save-dev gulp-rev\n```\n\n## Usage\n\n```js\nimport gulp from 'gulp';\nimport rev from 'gulp-rev';\n\nexport default () =\u003e (\n\tgulp.src('src/*.css')\n\t\t.pipe(rev())\n\t\t.pipe(gulp.dest('dist'))\n);\n```\n\n## API\n\n### rev()\n\n### rev.manifest(path?, options?)\n\n#### path\n\nType: `string`\\\nDefault: `'rev-manifest.json'`\n\nManifest file path.\n\n#### options\n\nType: `object`\n\n##### base\n\nType: `string`\\\nDefault: `process.cwd()`\n\nOverride the `base` of the manifest file.\n\n##### cwd\n\nType: `string`\\\nDefault: `process.cwd()`\n\nOverride the current working directory of the manifest file.\n\n##### merge\n\nType: `boolean`\\\nDefault: `false`\n\nMerge existing manifest file.\n\n##### transformer\n\nType: `object`\\\nDefault: `JSON`\n\nAn object with `parse` and `stringify` methods. This can be used to provide a\ncustom transformer instead of the default `JSON` for the manifest file.\n\n### Original path\n\nOriginal file paths are stored at `file.revOrigPath`. This could come in handy for things like rewriting references to the assets.\n\n### Asset hash\n\nThe hash of each rev'd file is stored at `file.revHash`. You can use this for customizing the file renaming, or for building different manifest formats.\n\n### Asset manifest\n\n```js\nimport gulp from 'gulp';\nimport rev from 'gulp-rev';\n\nexport default () =\u003e (\n\t// By default, Gulp would pick `assets/css` as the base,\n\t// so we need to set it explicitly:\n\tgulp.src(['assets/css/*.css', 'assets/js/*.js'], {base: 'assets'})\n\t\t.pipe(gulp.dest('build/assets'))  // Copy original assets to build dir\n\t\t.pipe(rev())\n\t\t.pipe(gulp.dest('build/assets'))  // Write rev'd assets to build dir\n\t\t.pipe(rev.manifest())\n\t\t.pipe(gulp.dest('build/assets'))  // Write manifest to build dir\n);\n```\n\nAn asset manifest, mapping the original paths to the revisioned paths, will be written to `build/assets/rev-manifest.json`:\n\n```json\n{\n\t\"css/unicorn.css\": \"css/unicorn-d41d8cd98f.css\",\n\t\"js/unicorn.js\": \"js/unicorn-273c2c123f.js\"\n}\n```\n\nBy default, `rev-manifest.json` will be replaced as a whole. To merge with an existing manifest, pass `merge: true` and the output destination (as `base`) to `rev.manifest()`:\n\n```js\nimport gulp from 'gulp';\nimport rev from 'gulp-rev';\n\nexport default () =\u003e (\n\t// By default, Gulp would pick `assets/css` as the base,\n\t// so we need to set it explicitly:\n\tgulp.src(['assets/css/*.css', 'assets/js/*.js'], {base: 'assets'})\n\t\t.pipe(gulp.dest('build/assets'))\n\t\t.pipe(rev())\n\t\t.pipe(gulp.dest('build/assets'))\n\t\t.pipe(rev.manifest({\n\t\t\tbase: 'build/assets',\n\t\t\tmerge: true // Merge with the existing manifest if one exists\n\t\t}))\n\t\t.pipe(gulp.dest('build/assets'))\n);\n```\n\nYou can optionally call `rev.manifest('manifest.json')` to give it a different path or filename.\n\n## Sourcemaps and `gulp-concat`\n\nBecause of the way `gulp-concat` handles file paths, you may need to set `cwd` and `path` manually on your `gulp-concat` instance to get everything to work correctly:\n\n```js\nimport gulp from 'gulp';\nimport rev from 'gulp-rev';\nimport sourcemaps from 'gulp-sourcemaps';\nimport concat from 'gulp-concat';\n\nexport default () =\u003e (\n\tgulp.src('src/*.js')\n\t\t.pipe(sourcemaps.init())\n\t\t.pipe(concat({path: 'bundle.js', cwd: ''}))\n\t\t.pipe(rev())\n\t\t.pipe(sourcemaps.write('.'))\n\t\t.pipe(gulp.dest('dist'))\n);\n```\n\n## Different hash for unchanged files\n\nSince the order of streams are not guaranteed, some plugins such as `gulp-concat` can cause the final file's content and hash to change. To avoid generating a new hash for unchanged source files, you can:\n\n- Sort the streams with [gulp-sort](https://github.com/pgilad/gulp-sort)\n- Filter unchanged files with [gulp-unchanged](https://github.com/sindresorhus/gulp-changed)\n- Read more about [incremental builds](https://github.com/gulpjs/gulp#incremental-builds)\n\n## Streaming\n\nThis plugin does not support streaming. If you have files from a streaming source, such as Browserify, you should use [`gulp-buffer`](https://github.com/jeromew/gulp-buffer) before `gulp-rev` in your pipeline:\n\n```js\nimport gulp from 'gulp';\nimport browserify from 'browserify';\nimport source from 'vinyl-source-stream';\nimport buffer from 'gulp-buffer';\nimport rev from 'gulp-rev';\n\nexport default () =\u003e (\n\tbrowserify('src/index.js')\n\t\t.bundle({debug: true})\n\t\t.pipe(source('index.min.js'))\n\t\t.pipe(buffer())\n\t\t.pipe(rev())\n\t\t.pipe(gulp.dest('dist'))\n);\n```\n\n## Integration\n\nFor more info on how to integrate `gulp-rev` into your app, have a look at the [integration guide](integration.md).\n\n## Use gulp-rev in combination with one or more of\n\nIt may be useful - and necessary - to use `gulp-rev` with other packages to complete the task.\n\n- [gulp-rev-rewrite](https://github.com/TheDancingCode/gulp-rev-rewrite) - Rewrite occurrences of filenames which have been renamed\n- [gulp-rev-css-url](https://github.com/galkinrost/gulp-rev-css-url) - Override URLs in CSS files with the revved ones\n- [gulp-rev-outdated](https://github.com/shonny-ua/gulp-rev-outdated) - Old static asset revision files filter\n- [gulp-rev-collector](https://github.com/shonny-ua/gulp-rev-collector) - Static asset revision data collector\n- [rev-del](https://github.com/callumacrae/rev-del) - Delete old unused assets\n- [gulp-rev-delete-original](https://github.com/nib-health-funds/gulp-rev-delete-original) - Delete original files after rev\n- [gulp-rev-dist-clean](https://github.com/alexandre-abrioux/gulp-rev-dist-clean) - Clean up temporary and legacy files created by gulp-rev \n- [gulp-rev-loader](https://github.com/adjavaherian/gulp-rev-loader) - Use rev-manifest with webpack\n- [gulp-rev-format](https://github.com/atamas101/gulp-rev-format) - Provide hash formatting options for static assets (prefix, suffix, last-extension)\n- [gulp-rev-sri](https://github.com/shaunwarman/gulp-rev-sri) - Add subresource integrity field to rev-manifest\n","funding_links":["https://github.com/sponsors/sindresorhus","https://opencollective.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-rev","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsindresorhus%2Fgulp-rev","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Fgulp-rev/lists"}