{"id":13671017,"url":"https://github.com/calvinmetcalf/rollup-plugin-node-globals","last_synced_at":"2025-04-06T15:13:33.935Z","repository":{"id":5624596,"uuid":"53545845","full_name":"calvinmetcalf/rollup-plugin-node-globals","owner":"calvinmetcalf","description":null,"archived":false,"fork":false,"pushed_at":"2022-12-09T07:39:50.000Z","size":511,"stargazers_count":90,"open_issues_count":38,"forks_count":22,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-03T02:37:50.094Z","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/calvinmetcalf.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":"2016-03-10T01:43:34.000Z","updated_at":"2024-11-16T15:00:01.000Z","dependencies_parsed_at":"2023-01-13T13:37:38.162Z","dependency_job_id":null,"html_url":"https://github.com/calvinmetcalf/rollup-plugin-node-globals","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/calvinmetcalf%2Frollup-plugin-node-globals","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/calvinmetcalf%2Frollup-plugin-node-globals/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/calvinmetcalf%2Frollup-plugin-node-globals/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/calvinmetcalf%2Frollup-plugin-node-globals/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/calvinmetcalf","download_url":"https://codeload.github.com/calvinmetcalf/rollup-plugin-node-globals/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247500469,"owners_count":20948880,"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-08-02T09:00:55.949Z","updated_at":"2025-04-06T15:13:33.913Z","avatar_url":"https://github.com/calvinmetcalf.png","language":"JavaScript","funding_links":[],"categories":["Plugins","JavaScript"],"sub_categories":["Modules"],"readme":"rollup-plugin-node-globals\n===\n\nPlugin to insert node globals including so code that works with browserify should work even if it uses process or buffers. This is based on [rollup-plugin-inject\n](https://github.com/rollup/rollup-plugin-inject).\n\n- process\n- global\n- Buffer\n- `__dirname`\n- `__filename`\n\nPlus `process.nextTick` and `process.browser` are optimized to only pull in\nthemselves and `__dirname` and `__filename` point to the file on disk\n\nThere are a few options to control output\n- `process` - pass `false` to disable process polyfilling\n- `global` - pass `false` to disable global polyfilling\n- `buffer` - pass `false` to disable Buffer polyfilling\n- `dirname` - pass `false` to disable `__dirname` polyfilling\n- `filename` - pass `false` to disable `__filename` polyfilling\n- `baseDir` which is used for resolving `__dirname` and `__filename`.\n\n# examples\n\n```js\nvar foo;\nif (process.browser) {\n  foo = 'bar';\n} else {\n  foo = 'baz';\n}\n```\n\nturns into\n\n```js\nimport {browser} from 'path/to/process';\nvar foo;\nif (browser) {\n  foo = 'bar';\n} else {\n  foo = 'baz';\n}\n```\n\nbut with rollup that ends up being\n\n```js\nvar browser = true;\nvar foo;\nif (browser) {\n  foo = 'bar';\n} else {\n  foo = 'baz';\n}\n```\n\nor\n\n```js\nvar timeout;\nif (global.setImmediate) {\n  timeout = global.setImmediate;\n} else {\n  timeout = global.setTimeout;\n}\nexport default timeout;\n```\n\nturns into\n\n```js\nimport {_global} from 'path/to/global.js';\nvar timeout;\nif (_global.setImmediate) {\n  timeout = _global.setImmediate;\n} else {\n  timeout = _global.setTimeout;\n}\nexport default timeout;\n\n```\n\nwhich rollup turns into\n\n```js\nvar _global = typeof global !== \"undefined\" ? global :\n            typeof self !== \"undefined\" ? self :\n            typeof window !== \"undefined\" ? window : {}\n\nvar timeout;\nif (_global.setImmediate) {\n  timeout = _global.setImmediate;\n} else {\n  timeout = _global.setTimeout;\n}\nvar timeout$1 = timeout;\n\nexport default timeout$1;\n```\n\nWith that top piece only showing up once no matter how many times global was used.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcalvinmetcalf%2Frollup-plugin-node-globals","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcalvinmetcalf%2Frollup-plugin-node-globals","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcalvinmetcalf%2Frollup-plugin-node-globals/lists"}