{"id":22814187,"url":"https://github.com/smackjax/html-webpack-inject-string-plugin","last_synced_at":"2025-10-07T21:10:32.233Z","repository":{"id":47642067,"uuid":"223049128","full_name":"smackjax/html-webpack-inject-string-plugin","owner":"smackjax","description":"A simple Webpack plugin that injects custom strings into the html-webpack-plugin output","archived":false,"fork":false,"pushed_at":"2022-09-03T14:56:06.000Z","size":468,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-06T10:40:42.978Z","etag":null,"topics":["customization","html-webpack-plugin","npm","simple","webpack"],"latest_commit_sha":null,"homepage":"","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/smackjax.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":"2019-11-20T23:48:54.000Z","updated_at":"2023-06-29T02:22:46.000Z","dependencies_parsed_at":"2022-09-26T19:42:41.437Z","dependency_job_id":null,"html_url":"https://github.com/smackjax/html-webpack-inject-string-plugin","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/smackjax%2Fhtml-webpack-inject-string-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smackjax%2Fhtml-webpack-inject-string-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smackjax%2Fhtml-webpack-inject-string-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smackjax%2Fhtml-webpack-inject-string-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/smackjax","download_url":"https://codeload.github.com/smackjax/html-webpack-inject-string-plugin/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246385414,"owners_count":20768672,"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":["customization","html-webpack-plugin","npm","simple","webpack"],"created_at":"2024-12-12T13:07:31.511Z","updated_at":"2025-10-07T21:10:27.208Z","avatar_url":"https://github.com/smackjax.png","language":"JavaScript","readme":"# HTML WEBPACK INJECT STRING PLUGIN\n## What's this?\nA dead simple plugin that searches each file output by html-webpack-plugin for a custom string(like a '\\\u003c/body\\\u003e' tag) and prepends, replaces, or appends a custom string by injecting it, then returning the completed template.\n\n## Install\n`npm i -D html-webpack-inject-string-plugin html-webpack-plugin`\n\n## Config default options \n```javascript\n\n{\n    // String to search for\n    search: \"\",\n    // String to inject\n    inject: \"\",\n    \n    // (optional)Injects before found string\n    prepend: true\n    // (optional)Replaces found string with injection\n    replace: false\n    // (optional)Injects after found string\n    append: false\n    \n    // (optional)Adds 'r\\n\\' before or after injection string\n    newline: { before: true, after: true }\n    // (optional)Enables console.log messages\n    dev: false\n}\n```\n\n## Usage (simple)\n``` javascript\nconst htmlWebpackInjectStringPlugin = require('html-webpack-inject-string-plugin');\n{   // ...webpack.config\n    plugins: [\n        // ...htmlWebpackPlugin({}),\n         \n        new htmlWebpackInjectStringPlugin({\n            // String to search for\n            search: \"\u003c/body\u003e\",\n            // String to inject\n            inject: \"\u003cscript\u003ealert('injected')\u003c/script\u003e\"\n            // Defaults to prepending injection before search string\n        }),\n    ]\n}\n```\n\n## Usage (complex)\n``` javascript\nconst htmlWebpackInjectStringPlugin = require('html-webpack-inject-string-plugin');\n{   // ...webpack.config\n    plugins: [\n        // ...htmlWebpackPlugin({}),\n        \n        new htmlWebpackInjectStringPlugin({\n            // String to search for\n            search: \"\u003cdiv id='replace-me'\u003e\u003c/div\u003e\",\n            // String to inject\n            inject: \"\u003cscript\u003ealert('injected')\u003c/script\u003e\",\n            \n            // NOTE: All three of these can be used at the same time\n            // which will inject the same string 3 times in a row\n            prepend: true,\n            replace: true,\n            append: true,\n            \n            // Removes '\\r\\n' before and after the injection\n            newline: false\n            \n            // Turns on console log messages if you want to see what it's doing\n            dev: true\n        }),\n    ]\n}\n```\n\n## Be aware\n* Backslashes may need to be escaped twice(three slashes total), because it's run through a compiler first. \n\n## Wait, isn't this a little dangerous?\nYep! \n\n## So why would I use it?\nBecause sometimes it's just incredibly helpful. \n\nFor instance I needed to inject a browser-sync script into each html-webpack file that contained a closing body tag.\nI didn't want the boilerplate of adding it individually and conditionally(just in dev mode) to each page.\n\nSo I made this plugin to add it automatically and only where and when it was needed. ","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmackjax%2Fhtml-webpack-inject-string-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsmackjax%2Fhtml-webpack-inject-string-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmackjax%2Fhtml-webpack-inject-string-plugin/lists"}