{"id":13798486,"url":"https://github.com/brrd/electron-require","last_synced_at":"2025-05-13T05:32:21.047Z","repository":{"id":57221878,"uuid":"54980381","full_name":"brrd/electron-require","owner":"brrd","description":"Simplified require in electron applications","archived":true,"fork":false,"pushed_at":"2016-07-06T18:51:49.000Z","size":13,"stargazers_count":26,"open_issues_count":1,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-24T00:40:47.645Z","etag":null,"topics":["electron","require"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/electron-require","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/brrd.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":"2016-03-29T13:59:37.000Z","updated_at":"2023-01-28T05:52:19.000Z","dependencies_parsed_at":"2022-08-29T04:10:15.049Z","dependency_job_id":null,"html_url":"https://github.com/brrd/electron-require","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/brrd%2Felectron-require","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brrd%2Felectron-require/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brrd%2Felectron-require/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brrd%2Felectron-require/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brrd","download_url":"https://codeload.github.com/brrd/electron-require/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253883137,"owners_count":21978611,"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":["electron","require"],"created_at":"2024-08-04T00:00:44.736Z","updated_at":"2025-05-13T05:32:20.591Z","avatar_url":"https://github.com/brrd.png","language":"JavaScript","readme":"# electron-require\n\n\u003e Simplified require in electron applications\n\n`electron-require` is a super basic, no dependency convenience wrapper around `require` for your electron applications. You can use it to avoid using complex require paths in your application.\n\n## Installation\n\n`$ npm install --save electron-require`\n\nThen include it in your code:\n\n```javascript\nconst rq = require('electron-require');\n```\n\n## Usage\n\n### `rq()`\n\n`rq('./module.js')` imports `module.js` from the current process directory (it is actually an alias to `require.main.require('./module.js')`).\n\n### `rq.electron()`\n\n`rq.electron('module')` is the same than `require('electron')['module']`, except that it resolves into `require('electron').remote['module']` when module is not found, if used in the renderer process.\n\n### `rq.remote()`\n\n`rq.remote('module')` is the same than `require('electron').remote.require('module')`, except that it resolves into `rq.main('module')` when used in the main process.\n\n### Aliases\n\nYou can add your own custom alias with `rq.set(key, path)`.\n\nOnce `rq.set('myAlias', 'my/path')` is called, `rq.myAlias('./module.js')` will try to load `my/path/module.js`.\n\n**Example 1:**\n\n```javascript\nrq.set('local', 'local');\n\n// Import [application root]/local/my-local-module.js into myLocalModule\nconst myLocalModule = rq.local('./my-local-module.js');\n```\n\n**Example 2:**\n\n```javascript\nlet userData = electron.app.getPath('userData');\nrq.set('plugin', userData + '/plugins');\n\n// Import [userdata]/plugins/my-plugin.js into myPlugin\nconst myPlugin = rq.plugin('/my-plugin.js');\n```\n\n#### Template strings\n\nYou can use template string in the `path` passed to `.set()`:\n\n* `%{app}` resolves to `app.getAppPath()`\n* `%{anyOtherName}` resolves to `app.getPath('anyOtherName')`\n\nSo we can write example 2 in a simpler way:\n\n```javascript\nrq.set('plugin', '%{userData}/plugins');\n\n// Import [userdata]/plugins/my-plugin.js into myPlugin\nconst myPlugin = rq.plugin('/my-plugin.js');\n```\n\nRead more about this in [the app module documentation](https://github.com/electron/electron/blob/master/docs/api/app.md)\n\n#### Multiple alias\n\n`rq.set` can also be used with an object:\n\n```javascript\nrq.set({\n\t'local': 'local',\n    'plugin': '%{userData}/plugins'\n});\n```\n\n#### Custom aliases defined in package.json\n\nIn most cases you will want to use the same custom aliases for the whole project. You can define custom aliases by adding an `electron-require` key to your app `package.json` file:\n\n```json\n\"electron-require\": {\n    \"first\": \"path/to/first/alias\",\n\t\"second\": \"path/to/second/alias\"\n}\n```\n\n#### Default aliases\n\nDefault aliases are the following:\n\n```json\n{\n    \"root\": \"\",\n    \"renderer\": \"app/renderer\",\n    \"main\": \"app/main\",\n    \"browser\": \"app/main\"\n}\n```\n\nIt actually assumes that your app is organized in the following way:\n\n```\n.\n├── app\n│   ├── main\n│   │   └── [main process modules]\n│   └── renderer\n│       └── [renderer process modules]\n└── package.json\n```\n\nBut you can of course override theses default values by using `rq.set()` or by adding an `electron-require` entry in your `package.json`.\n\n## License\n\nThe MIT License (MIT)  \nCopyright (c) 2016 Thomas Brouard\n","funding_links":[],"categories":["Library","Tools"],"sub_categories":["Uncategorized","For Electron"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrrd%2Felectron-require","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrrd%2Felectron-require","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrrd%2Felectron-require/lists"}