{"id":20627802,"url":"https://github.com/sivan/gulp-assets-plus","last_synced_at":"2025-04-15T15:35:32.936Z","repository":{"id":57256846,"uuid":"54630733","full_name":"sivan/gulp-assets-plus","owner":"sivan","description":"md5/sha256 the static files(eg. javascript, style, image files) and change the hash strings in the quoted file.","archived":false,"fork":false,"pushed_at":"2017-02-20T06:34:09.000Z","size":11,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-28T21:51:10.729Z","etag":null,"topics":[],"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/sivan.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-03-24T09:34:41.000Z","updated_at":"2023-03-08T14:26:00.000Z","dependencies_parsed_at":"2022-08-25T02:40:45.684Z","dependency_job_id":null,"html_url":"https://github.com/sivan/gulp-assets-plus","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sivan%2Fgulp-assets-plus","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sivan%2Fgulp-assets-plus/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sivan%2Fgulp-assets-plus/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sivan%2Fgulp-assets-plus/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sivan","download_url":"https://codeload.github.com/sivan/gulp-assets-plus/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249098862,"owners_count":21212570,"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":[],"created_at":"2024-11-16T13:18:17.355Z","updated_at":"2025-04-15T15:35:32.900Z","avatar_url":"https://github.com/sivan.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gulp-assets-plus\n\nmd5/sha256 the static files(eg. javascript, style, image files) and change the hash strings in the quoted file. Forked from [gulp-md5-assets](https://github.com/stipsan/gulp-md5-assets).\n\n``` html\n\u003clink rel=\"stylesheet\" href=\"./css/main.css\" /\u003e\n=\u003e\n\u003clink rel=\"stylesheet\" href=\"./css/main.css?56318d54ed\" /\u003e\n```\n``` css\n.gf {\n  background-image: url(./img/goldenfinger.jpg);\n}\n=\u003e\n.gf {\n  background-image: url(./img/goldenfinger.jpg?56318d54ed);\n}\n```\n\n## Usage\n\nFirst, install `gulp-assets-plus` as a development dependency:\n\n``` shell\nnpm i --save-dev gulp-assets-plus\n```\n\nThen, add the code below to your `gulpfile.js`.\n\nExample 1: Md5 all css files in the src folder and change these css names in the quoted html.\n\n``` js\nvar hashAssets = require(\"gulp-assets-plus\");\n\ngulp.src(\"./src/*.css\")\n  .pipe(hashAssets('./output/*.html'))\n  .pipe(gulp.dest(\"./dist\")\n);\n```\n\nExample 2: First, optimize all images in the img folder including all sub folders; then sha256 all these images limited to a length of 6 and change these images'names in the quoted css files.\n\n``` js\ngulp.task('img' ,function() {\n  var imgSrc = './static/img/**';\n  var quoteSrc = './output/static/css/**/*.css',\n  var imgDst = './output/static/img';\n\n  return gulp.src(imgSrc)\n    .pipe(imagemin())\n    .pipe(hashAssets(quoteSrc, {\n      size: 6,\n      algorithm: 'sha256'\n    }))\n    .pipe(gulp.dest(imgDst));\n});\n```\n\n#### note\n\nthe directory of the md5ed files in the imgDst folder is the same as that of original files in the imgSrc folder; and css files can refer the image file with the same name in different folder rightly.\n\n## API\n\n### hashAssets(file, opt)\n\n#### file\n\nType: `String`\n\nDefault: null\n\nOptionnal: the file need to replace the file name of the hashed files. Dir is also supported.\n\nExample:\n\n``` javascript\ngulp.src('static/js/*')\n  .pipe(hashAssets('./output/html/*.html'), {size: 6})\n  .pipe(gulp.dest('./output')\n);\n```\n\nThe sample above will append the md5 hash(length: 6) to each of the file in the `static/js` folder then repalce the link file name in the `output/html/` using md5ed file name; at last store all of that into the `output` folder.\n\n#### opt\n\n##### opt.size\n\nType: `String`\n\nDefault: 7\n\nOptionnal: you can pass the size to limit the size of the hash that is appended.\n\n##### opt.assetsPath\n\nType: `String`\n\nDefault: null\n\nOptionnal: you can declare the assets folder manually when the assets path is different to the quoted source.\n\nExample:\n\n``` html\n\u003clink rel=\"stylesheet\" href=\"http://127.0.0.1/css/main.css?56318d54ed\" /\u003e\n```\n``` javascript\ngulp.src('dist/css/**/*.css')\n  .pipe(hashAssets('./output/html/*.html'), {\n    assetsPath: 'dist/'\n  })\n  .pipe(gulp.dest('./output')\n);\n```\n\n##### opt.quotedPath\n\nType: `String`\n\nDefault: null\n\nOptionnal: you can declare the quotes folder manually when quoted source is diffrent from actual Path (rewritten).\n\nExample:\n\n``` html\n\u003clink rel=\"stylesheet\" href=\"http://127.0.0.1/rewrite_to_css/main.css?56318d54ed\" /\u003e\n```\n``` javascript\ngulp.src('css/**/*.css')\n  .pipe(hashAssets('./output/html/*.html'), {\n    quotedPath: 'rewrite_to_css/'\n  })\n);\n```\n\n\n##### opt.whitelist\n\nType: `String` | `Array`\n\nDefault: null\n\nOptionnal: you can pass a whitelist array to filter the files you don't want to add the hash. For example: use `['base', 'jquery']` will ignore all the files which contains 'base' or 'jquery' in the filename, it's useful when you don't want to add hash to some file.\n\n##### opt.ignore\n\nType: `String` | `Array`\n\nDefault: null\n\nOptionnal: you can pass an ignore string/array to filter the files with this hash. For example: use `['debug']` or `'debug'` will ignore these files when you quote them like `\u003clink rel=\"stylesheet\" href=\"./css/main.css?debug\" /\u003e`. It's useful when you change some file frequently during development, but don't forget to remove that string before publish.\n\n##### opt.algorithm\n\nType: `String`\n\nDefault: 'md5'\n\nOptionnal: generate hash digests using the given algorithm. On recent releases of OpenSSL, `openssl list-message-digest-algorithms` will display the available digest algorithms. See more at [Node.js Documentation](https://nodejs.org/api/crypto.html#crypto_crypto_createhash_algorithm).\n\n## License\n\nMIT License\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsivan%2Fgulp-assets-plus","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsivan%2Fgulp-assets-plus","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsivan%2Fgulp-assets-plus/lists"}