{"id":15251119,"url":"https://github.com/exuanbo/gulp-source-injector","last_synced_at":"2025-04-10T20:11:16.446Z","repository":{"id":40309414,"uuid":"256353165","full_name":"exuanbo/gulp-source-injector","owner":"exuanbo","description":"Injects any source into any file.","archived":false,"fork":false,"pushed_at":"2025-02-14T19:11:39.000Z","size":260,"stargazers_count":2,"open_issues_count":28,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-06T06:57:04.215Z","etag":null,"topics":["css","gulp","gulp-inject","gulpplugin","html","inject","javascript","webcomponent"],"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/exuanbo.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":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-04-16T23:30:43.000Z","updated_at":"2021-01-20T13:21:00.000Z","dependencies_parsed_at":"2023-07-17T07:46:34.468Z","dependency_job_id":"7cc5a715-287a-47b8-bca7-ee9098505229","html_url":"https://github.com/exuanbo/gulp-source-injector","commit_stats":{"total_commits":153,"total_committers":4,"mean_commits":38.25,"dds":0.3921568627450981,"last_synced_commit":"27488763e4aa7d2f5f206e18a1103ca2ce624e86"},"previous_names":["exuanbo/gulp-inject-inline"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/exuanbo%2Fgulp-source-injector","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/exuanbo%2Fgulp-source-injector/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/exuanbo%2Fgulp-source-injector/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/exuanbo%2Fgulp-source-injector/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/exuanbo","download_url":"https://codeload.github.com/exuanbo/gulp-source-injector/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248288357,"owners_count":21078903,"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":["css","gulp","gulp-inject","gulpplugin","html","inject","javascript","webcomponent"],"created_at":"2024-09-29T17:06:42.874Z","updated_at":"2025-04-10T20:11:16.426Z","avatar_url":"https://github.com/exuanbo.png","language":"JavaScript","funding_links":["https://www.buymeacoffee.com/exuanbo"],"categories":[],"sub_categories":[],"readme":"# gulp-source-injector\n\n\u003e Injects any source into any file.\n\n[![npm](https://img.shields.io/npm/v/gulp-source-injector.svg?style=flat-square)](https://www.npmjs.com/package/gulp-source-injector)\n[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg?style=flat-square)](https://standardjs.com)\n[![Travis (.com)](https://img.shields.io/travis/com/exuanbo/gulp-source-injector/master.svg?style=flat-square)](http://travis-ci.com/exuanbo/gulp-source-injector)\n[![David](https://img.shields.io/david/exuanbo/gulp-source-injector.svg?style=flat-square)](https://david-dm.org/exuanbo/gulp-source-injector)\n[![License](https://img.shields.io/github/license/exuanbo/gulp-source-injector.svg?style=flat-square)](https://github.com/exuanbo/gulp-source-injector/blob/master/LICENSE)\n\n## Table of Contents\n\n- [Description](#description)\n- [Install](#install)\n- [Usage](#usage)\n- [Example](#example)\n  - [Indentation](#indentation)\n- [License](#license)\n\n## Description\n\n`gulp-source-injector` transforms content of each source file to a string and injects each transformed string into placeholders in the target stream files.\n\nThis plugin does not do any minification to source files, so whitespaces will be preserved. It's better to use it after transformations like `gulp-terser` or `gulp-clean-css`.\n\n## Install\n\n```bash\nnpm install --save-dev gulp-source-injector\n```\n\n## Usage\n\nInjection placeholders are comments as html syntax `\u003c!-- inject: filePath --\u003e` and css/js syntax `/* inject: filePath */`\n\nBy default the injected file path is relative to each target file's `cwd`. If the provided path starts with `/`, it will be considered relative to the directory of `gulpfile.js`\n\n## Example\n\nProject structure\n\n```bash\n├── src\n│   ├── css\n│   │   └── style.css\n│   ├── js\n│   │   └── script.js\n│   ├── template\n│   │   └── head.html\n│   └── index.html\n└── gulpfile.js\n```\n\nTarget file `src/index.html`\n\n```html\n\u003chtml\u003e\n  \u003chead\u003e\n    \u003c!-- inject: /src/template/head.html --\u003e\n    \u003cstyle\u003e\n      /* inject: ./css/style.css */\n    \u003c/style\u003e\n    \u003cscript\u003e\n      /*inject:js/script.js*/\n    \u003c/script\u003e\n  \u003c/head\u003e\n  \u003cbody\u003e\n    \u003ch1\u003eLorem Ipsum\u003c/h1\u003e\n  \u003c/body\u003e\n\u003c/html\u003e\n```\n\n`gulpfile.js`\n\n```javascript\nconst { task, src, dest } = require('gulp')\nconst inject = require('gulp-source-injector')\n\ntask('inject', () =\u003e {\n  return src('src/index.html')\n    .pipe(inject())\n    .pipe(dest('dist'))\n})\n```\n\nor you can\n\n```javascript\nimport inject from 'gulp-source-injector'\n```\n\nand then\n\n`dist/index.html` after running `gulp inject`\n\n```html\n\u003chtml\u003e\n  \u003chead\u003e\n    \u003cmeta charset=\"utf-8\"\u003e\n    \u003cmeta name=\"viewport\" content=\"width=device-width\"\u003e\n    \u003cmeta title=\"test\"\u003e\n    \u003cstyle\u003e\n      body {\n        background-color: #333;\n      }\n      h1 {\n        color: #EEE;\n      }\n    \u003c/style\u003e\n    \u003cscript\u003e\n      console.log('foobar')\n    \u003c/script\u003e\n  \u003c/head\u003e\n  \u003cbody\u003e\n    \u003ch1\u003eLorem Ipsum\u003c/h1\u003e\n  \u003c/body\u003e\n\u003c/html\u003e\n```\n\n### Indentation\n\nNote that existing indentation won't be preserved.\n\nTarget file `src/index.html`\n\n```html\n\u003chtml\u003e\n  \u003chead\u003e\n    \u003cstyle\u003e\n      /* inject: ./css/style.css */\n    \u003c/style\u003e\n  \u003c/head\u003e\n  \u003cbody\u003e\n    \u003ch1\u003eLorem Ipsum\u003c/h1\u003e\n  \u003c/body\u003e\n\u003c/html\u003e\n```\n\nSource file `src/css/style.css`\n\n```css\nbody {\n  background-color: #333;\n}\nh1 {\n  color: #EEE;\n}\n```\n\n`dist/index.html`\n\n```html\n\u003chtml\u003e\n  \u003chead\u003e\n    \u003cstyle\u003e\n      body {\n  background-color: #333;\n}\nh1 {\n  color: #EEE;\n}\n    \u003c/style\u003e\n  \u003c/head\u003e\n  \u003cbody\u003e\n    \u003ch1\u003eLorem Ipsum\u003c/h1\u003e\n  \u003c/body\u003e\n\u003c/html\u003e\n```\n\n## License\n\n[MIT](https://github.com/exuanbo/gulp-source-injector/blob/master/LICENSE)\n\n## Donate\n\n\u003ca href=\"https://www.buymeacoffee.com/exuanbo\" target=\"_blank\"\u003e\u003cimg src=\"https://cdn.buymeacoffee.com/buttons/lato-orange.png\" alt=\"Buy Me A Coffee\" height=\"38.25px\" width=\"162.75px\"\u003e\u003c/a\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexuanbo%2Fgulp-source-injector","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fexuanbo%2Fgulp-source-injector","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexuanbo%2Fgulp-source-injector/lists"}