{"id":30261655,"url":"https://github.com/peerigon/legacy-loader","last_synced_at":"2025-08-15T20:55:25.465Z","repository":{"id":26731495,"uuid":"30189064","full_name":"peerigon/legacy-loader","owner":"peerigon","description":"Webpack loader that prevents scripts from extending the window object.","archived":false,"fork":false,"pushed_at":"2020-08-27T12:57:07.000Z","size":29,"stargazers_count":12,"open_issues_count":1,"forks_count":3,"subscribers_count":16,"default_branch":"master","last_synced_at":"2025-08-09T09:47:28.502Z","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":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/peerigon.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}},"created_at":"2015-02-02T13:49:22.000Z","updated_at":"2022-05-27T12:04:33.000Z","dependencies_parsed_at":"2022-09-01T07:21:50.838Z","dependency_job_id":null,"html_url":"https://github.com/peerigon/legacy-loader","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/peerigon/legacy-loader","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peerigon%2Flegacy-loader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peerigon%2Flegacy-loader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peerigon%2Flegacy-loader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peerigon%2Flegacy-loader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/peerigon","download_url":"https://codeload.github.com/peerigon/legacy-loader/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peerigon%2Flegacy-loader/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270483479,"owners_count":24591567,"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","status":"online","status_checked_at":"2025-08-14T02:00:10.309Z","response_time":75,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":[],"created_at":"2025-08-15T20:55:21.147Z","updated_at":"2025-08-15T20:55:25.460Z","avatar_url":"https://github.com/peerigon.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# legacy-loader\n\n**[Webpack](http://webpack.github.io/) loader that prevents scripts from extending the window object**\n\n[![Build Status](https://travis-ci.org/peerigon/legacy-loader.svg?branch=master)](https://travis-ci.org/peerigon/legacy-loader)\n[![Dependency Status](https://david-dm.org/peerigon/legacy-loader.svg)](https://david-dm.org/peerigon/legacy-loader)\n[![Coverage Status](https://img.shields.io/coveralls/peerigon/legacy-loader.svg)](https://coveralls.io/r/peerigon/legacy-loader?branch=master)\n\nUse this loader to cope with legacy scripts that extend the window object instead of using AMD or CommonJS.\n\n**Please note: There is a major issue with the current approach of this loader, see [#1](https://github.com/peerigon/legacy-loader/issues/1). Use at your own risk!**\n\n\u003cbr /\u003e\n\n## Installation\n\n[![npm status](https://nodei.co/npm/legacy-loader.svg?downloads=true\u0026stars=true)](https://npmjs.org/package/legacy-loader)\n\n\u003cbr /\u003e\n\n## Usage\n\n### Basic example\n\nImagine you've downloaded `some-legacy-script` from npm which looks like\n\n```javascript\nwindow.someLegacyScript = function () {\n    console.log(\"Yay!\");\n};\n```\n\nNow just run `npm i legacy-loader --save` and configure your `webpack.config.js` like this\n\n```javascript\nmodule.exports = {\n    module: {\n        loaders: [\n            {\n                test: /[\\/\\\\]node_modules[\\/\\\\]some-legacy-script[\\/\\\\]index\\.js$/,\n                loader: \"legacy\",\n            },\n        ],\n    },\n};\n```\n\nthen you can do\n\n```javascript\nvar someLegacyScript = require(\"some-legacy-script\");\n\nsomeLegacyScript(); // prints 'Yay!'\nwindow.someLegacyScript; // undefined\n```\n\n### Auto export\n\nThe **legacy-loader** exports a single value via `module.exports` when your legacy script did only add one\nproperty to the window object. If it added two or more, an object is returned instead:\n\n```javascript\n// node_modules/some-legacy-script/index.js\n\nwindow.propertyA = true;\nwindow.propertyB = false;\n```\n\n```javascript\n// app.js\n\nvar someLegacyScript = require(\"some-legacy-script\");\n\nsomeLegacyScript.propertyA; // true\nsomeLegacyScript.propertyB; // false\n\nwindow.propertyA; // undefined\nwindow.propertyB; // undefined\n```\n\n### Specific exports\n\nWhen your legacy script adds two or more properties, but you're still just interested in one particular property,\nyou can also pass a property name:\n\n```javascript\n// webpack.config.js\n\n    ...\n    {\n        test: /[\\/\\\\]node_modules[\\/\\\\]some-legacy-script[\\/\\\\]index\\.js$/,\n        loader: \"legacy?exports=propertyA\"\n    }\n    ...\n```\n\n```javascript\n// app.js\n\nvar someLegacyScript = require(\"some-legacy-script\");\n\nsomeLegacyScript; // true -\u003e propertyA\n```\n\n### Publish\n\nSometimes other libraries are relying on a particular global variable (like jQuery plugins rely on `$`). Then you should\nfirst consider using the [imports-loader](https://github.com/webpack/imports-loader) to inject that variable into the\nprivate module scope. If this is not an option for you (e.g. because you're not loading this module via webpack),\nyou can decide to publish a single property back to the window object.\n\n```javascript\n// webpack.config.js\n\n    ...\n    {\n        test: /[\\/\\\\]node_modules[\\/\\\\]some-legacy-script[\\/\\\\]index\\.js$/,\n        loader: \"legacy?publish=propertyB\"\n    }\n    ...\n```\n\n```javascript\n// app.js\n\nvar someLegacyScript = require(\"some-legacy-script\");\n\nsomeLegacyScript.propertyA; // true\nsomeLegacyScript.propertyB; // false\n\nwindow.propertyA; // undefined\nwindow.propertyB; // false\n```\n\n\u003cbr /\u003e\n\n## Under the hood\n\nThe **legacy-loader** creates a window shim by inheriting from window via `Object.create(window)`. Thus the\nlegacy script receives a window-like object, without being able to extend it. Of course, this approach has\nthe usual limitations implied by the prototype inheritance (such as iterating over `window` while checking for\n`hasOwnProperty`).\n\n\u003cbr /\u003e\n\n## Contributing\n\nFrom opening a bug report to creating a pull request: **every contribution is appreciated and welcome**. If you're planing to implement a new feature or change the api please create an issue first. This way we can ensure that your precious work is not in vain.\n\nAll pull requests should have 100% test coverage (with notable exceptions) and need to pass all tests.\n\n-   Call `npm test` to run the unit tests\n-   Call `npm run coverage` to check the test coverage (using [istanbul](https://github.com/gotwarlost/istanbul))\n\n\u003cbr /\u003e\n\n## License\n\nUnlicense\n\n## Sponsors\n\n[\u003cimg src=\"https://assets.peerigon.com/peerigon/logo/peerigon-logo-flat-spinat.png\" width=\"150\" /\u003e](https://peerigon.com)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeerigon%2Flegacy-loader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpeerigon%2Flegacy-loader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeerigon%2Flegacy-loader/lists"}