{"id":15387007,"url":"https://github.com/gkjohnson/webpack-script-guard","last_synced_at":"2026-04-16T08:35:48.607Z","repository":{"id":66338491,"uuid":"97657960","full_name":"gkjohnson/webpack-script-guard","owner":"gkjohnson","description":"Webpack loader for guarding against duplicate scripts in separate bundles","archived":false,"fork":false,"pushed_at":"2017-11-05T23:16:35.000Z","size":265,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-11-13T22:54:31.769Z","etag":null,"topics":["deduplicate","deduplication","html","import","imports","javascript","loader","polymer","webcomponents","webpack"],"latest_commit_sha":null,"homepage":"","language":"HTML","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/gkjohnson.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-07-19T01:10:19.000Z","updated_at":"2025-01-31T20:57:22.000Z","dependencies_parsed_at":"2023-02-24T17:16:15.583Z","dependency_job_id":null,"html_url":"https://github.com/gkjohnson/webpack-script-guard","commit_stats":{"total_commits":15,"total_committers":1,"mean_commits":15.0,"dds":0.0,"last_synced_commit":"b989f0417b460aaed4274796d14c0106d8fc4ae7"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/gkjohnson/webpack-script-guard","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gkjohnson%2Fwebpack-script-guard","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gkjohnson%2Fwebpack-script-guard/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gkjohnson%2Fwebpack-script-guard/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gkjohnson%2Fwebpack-script-guard/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gkjohnson","download_url":"https://codeload.github.com/gkjohnson/webpack-script-guard/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gkjohnson%2Fwebpack-script-guard/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31878114,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-16T07:36:03.521Z","status":"ssl_error","status_checked_at":"2026-04-16T07:35:53.576Z","response_time":69,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["deduplicate","deduplication","html","import","imports","javascript","loader","polymer","webcomponents","webpack"],"created_at":"2024-10-01T14:51:17.994Z","updated_at":"2026-04-16T08:35:48.575Z","avatar_url":"https://github.com/gkjohnson.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# webpack-script-guard\n\n[![npm version](https://badge.fury.io/js/%40gkjohnson%2Fwebpack-script-guard.svg)](https://www.npmjs.com/package/@gkjohnson/webpack-script-guard)\n\nWebpack loader that adds a guard based on the source hash around running script content so the same guarded script cannot be included twice.\n\n## Goal\n\nWebcomponents and HTML imports are designed to be self-contained and droppable, but either require a number of polyfills or other framework to support their inclusion. Building a single, self contained `.js` file per import enables a single-file, cross-platform ease-of-use, but can't benefit from the deduping that HTML imports enable, causing runtime errors from code redundancy.\n\nWebpack-script-guard aims to solve this by guarding against execution of a script if it has already been included in a sibling webpack bundle (that used this same loader).\n\n## Problem Example\n\nConsider two web components with the following hierarchies output to two bundles `element-a.bundle.js` and `element-b.bundle.js` using something like [wc-loader](https://github.com/aruntk/wc-loader)\n\n**Element A**\n```\nelement-a.html\n| common-element.html\n| | polymer.html\n| polymer.html\n```\n\n**Element B**\n```\nelement-b.html\n| common-element.html\n| | polymer.html\n| polymer.html\n```\n\nNormally, in a single project, any redundant elements like `polymer.html` and `common-element.html` would be deduped during import or webpack. However, including the two bundles produced from these two elements separately will cause errors on the page from Polymer and `common-element` being included multiple times.\n\n## Use\nUse webpack-script-guard on any javascript output from a weback loader or a javascript file:\n```javascript\n{\n  test: /.html$/,\n  use: [\n    { loader: 'babel-loader' },\n    { loader: 'webpack-script-guard' },\n    { loader: 'wc-loader' }\n  ]\n}\n```\n\n## Gotchas\nThe guard does not work in every case. For example, when Polymer is included separately in the application without being packed with this plugin, the errors will still occur. It is suggested that elements be packed in a `full` and `lite` way such that external applications with problems can import dependency libraries themselves.\n\n```html\n\u003clink rel=\"import\" href=\".../polymer.html\" /\u003e\n\u003cscript src=\".../element-a.bundle.js\" /\u003e\n\u003c!-- run time error! --\u003e\n```\n\n## Approach\nWebpack-script-guard is a loader that hashes the source of a file and wraps the source in a conditional that will only execute if a corresponding hash has not already been run\n``` javascript\nif(!window.__scriptguards__['\u003csourcehash\u003e']) {\n  window.__scriptguards__['\u003csourcehash\u003e'] = true\n  // ... run script\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgkjohnson%2Fwebpack-script-guard","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgkjohnson%2Fwebpack-script-guard","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgkjohnson%2Fwebpack-script-guard/lists"}