{"id":16485825,"url":"https://github.com/creeperyang/gulp-useref-cdn","last_synced_at":"2025-10-19T18:41:59.591Z","repository":{"id":36056691,"uuid":"40355180","full_name":"creeperyang/gulp-useref-cdn","owner":"creeperyang","description":"Parse build blocks in HTML files to replace references and automatically upload to qiniu cdn.","archived":false,"fork":false,"pushed_at":"2015-08-07T13:52:58.000Z","size":136,"stargazers_count":6,"open_issues_count":2,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-01T07:41:14.219Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/creeperyang.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-08-07T10:28:24.000Z","updated_at":"2017-03-14T01:28:20.000Z","dependencies_parsed_at":"2022-08-25T03:53:17.847Z","dependency_job_id":null,"html_url":"https://github.com/creeperyang/gulp-useref-cdn","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/creeperyang%2Fgulp-useref-cdn","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/creeperyang%2Fgulp-useref-cdn/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/creeperyang%2Fgulp-useref-cdn/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/creeperyang%2Fgulp-useref-cdn/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/creeperyang","download_url":"https://codeload.github.com/creeperyang/gulp-useref-cdn/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238536191,"owners_count":19488671,"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-10-11T13:27:23.735Z","updated_at":"2025-10-19T18:41:59.487Z","avatar_url":"https://github.com/creeperyang.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# [gulp](https://github.com/gulpjs/gulp)-useref-cdn \n\n[![Build Status](https://travis-ci.org/creeperyang/gulp-useref-cdn.svg)](https://travis-ci.org/creeperyang/gulp-useref-cdn)\n\n\u003e Parse build blocks in HTML files to replace references and automatically upload to **qiniu** cdn.\n\nInspired by [grunt-useref](https://github.com/pajtai/grunt-useref) and [gulp-useref](https://github.com/jonkemp/gulp-useref). It can handle file concatenation but not minification. And it can upload the concatenated file to cdn automatically. Files are then passed down the stream. For minification of assets or other modifications, use [gulp-if](https://github.com/robrich/gulp-if) to conditionally handle specific types of assets.\n\n**Note**: lot of code from [gulp-useref](https://github.com/jonkemp/gulp-useref). `gulp-useref` doesn't apply a way to manage html file analysis or a callback after html file analysis. This is why I don't make `gulp-useref` as lib dependency and rewrite based on it.\n\n## Install\n\nInstall with [npm](https://npmjs.org/package/gulp-useref-cdn)\n\n```\nnpm install --save-dev gulp-useref-cdn\n```\n\n\n## Usage\n\nThe following example will parse the build blocks in the HTML, replace them, upload to cdn, and pass those files through. Assets inside the build blocks will be concatenated and passed through in a stream as well.\n\n```js\nvar gulp = require('gulp'),\n    useref = require('gulp-useref-cdn');\n\ngulp.task('default', function () {\n    var assets = useref.assets();\n\n    return gulp.src('app/*.html')\n        .pipe(assets)\n        .pipe(assets.restore())\n        .pipe(useref())\n        .pipe(gulp.dest('dist'));\n});\n```\n\nMore details: \u003chttps://github.com/jonkemp/gulp-useref\u003e. All `gulp-useref`'s syntax and usage are supported by `gulp-useref-cdn`.\n\n**What's important here is that an extended syntax/usage is added!**\n\n\n```html\n\u003c!-- build:\u003ctype\u003e(alternate search path) \u003cpath\u003e \u003cattrs\u003e --\u003e\n```\n\nBefore, **type** could be either `js`, `css` or `remove`. And the **new `cdn`** is added now.\n\nWhen you use `cdn` as the type, no need to write `js` or `css` anymore. The plugin will detect it automatically, and it will do the work as expected when you use `js|css`.\n\n**And with the `cdn` type, the plugin will upload the concatenated file to `qiniu` cdn.**\n\nAn example of this in completed form can be seen below:\n\n```html\n\u003chtml\u003e\n\u003chead\u003e\n    \u003c!-- build:cdn css/combined.css --\u003e\n    \u003clink href=\"css/one.css\" rel=\"stylesheet\"\u003e\n    \u003clink href=\"css/two.css\" rel=\"stylesheet\"\u003e\n    \u003c!-- endbuild --\u003e\n\u003c/head\u003e\n\u003cbody\u003e\n    \u003c!-- build:cdn scripts/combined.js \u003cbucket='xxx'\u003e \u003ckey='yyy'\u003e--\u003e\n    \u003cscript type=\"text/javascript\" src=\"scripts/one.js\"\u003e\u003c/script\u003e\n    \u003cscript type=\"text/javascript\" src=\"scripts/two.js\"\u003e\u003c/script\u003e\n    \u003c!-- endbuild --\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n```\n\n```js\nimport cdn from 'gulp-useref-cdn';\nlet assets = cdn.assets({\n    accessKey: 'ACCESS_KEY',\n    secretKey: 'SECRET_KEY',\n    domain: 'DOMAIN',\n    bucket: 'BUCKET', // could be replaced if you rewrite at html \u003cbucket='xxx'\u003e\n    keyPrefix: ''\n});\n\ngulp.src('test/fixtures/cdn.html')\n    .pipe(assets)\n    .on('error', (err) =\u003e {\n        done(err);\n    })\n    .pipe(assets.restore())\n    .pipe(cdn())\n    .pipe(gulp.dest('dist'));\n```\n\n\nThe resulting HTML would be:\n\n```html\n\u003chtml\u003e\n\u003chead\u003e\n    \u003clink rel=\"stylesheet\" href=\"http://7xkuzg.com1.z0.glb.clouddn.com/combined-f9ebd308.css\"/\u003e\n\u003c/head\u003e\n\u003cbody\u003e\n    \u003cscript src=\"http://7xkuzg.com1.z0.glb.clouddn.com/combined-ce2a0c47.js\"\u003e\u003c/script\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n```\n\nAnd you will see `combined-ce2a0c47.js` and `combined-f9ebd308.css` in your qiniu cdn's bucket.\n\n## API\n\n### useref(options)\n\nReturns a stream with the asset replaced resulting HTML files. Supports all options from [useref](https://github.com/digisfera/useref).\n\n### useref.assets(options)\n\nReturns a stream with the concatenated asset files from the build blocks inside the HTML.\n\n#### options.searchPath\n\nType: `String` or `Array`  \nDefault: `none`  \n\nSpecify the location to search for asset files, relative to the current working directory. Can be a string or array of strings.\n\n#### options.noconcat\n\nType: `Boolean`  \nDefault: `false`  \n\nSkip concatenation and add all assets to the stream instead.\n\n#### options.silent\n\nType: `Boolean`  \nDefault: `true`  \n\nSet to `false` if you want to see messages except error.\n\n#### options.md5\n\nType: `Number`  \nDefault: `8`  \n\n#### options.keyPrefix\n\nType: `String`  \nDefault: `gulp-useref-cdn/`  \n\nThe above two are all about `key`. `Key` is defined by [Qiniu](http://developer.qiniu.com/docs/v6/api/overview/concepts.html#resource). Key can be set clearly via `\u003ckey='yyy'\u003e` in comment.\n\nWhen `key` is not offered, plugin will generate the `key`:\n\n```js\nprefix + filename + '-' + md5 + '.' + filetype;\n```\n\n- `prefix` --- `options.keyPrefix`\n- `md5` --- the md5 string of the file, `options.md5` specify md5's length(after cut).\n- `filename`, `filetype` are offered by plugin.\n\n### stream.restore()\n\nBrings back the previously filtered out HTML files.\n\n## License\n\nCopyright (c) 2015 creeperyang. Licensed under the MIT license.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcreeperyang%2Fgulp-useref-cdn","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcreeperyang%2Fgulp-useref-cdn","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcreeperyang%2Fgulp-useref-cdn/lists"}