From 46af3cefec37e13fa03d4b52c155fcb555dcbf40 Mon Sep 17 00:00:00 2001 From: Bret Comnes Date: Mon, 13 Mar 2017 15:42:26 -0700 Subject: [PATCH] Clarify remote require of relative modules The docs for the `remote.require(module)` method were a little too terse for me to understand the behavior of relative module loading for `remote.require` and I had to run an experiment to understand the behavior (e.g. is the relative path relative to caller of `remote.require` or relative to some other path in the project related to the main process?). I think this is correct but someone please double check my understanding. Adding an example and additional explanation should help clarify this. Feel free to edit the copy as needed. --- docs/api/remote.md | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/docs/api/remote.md b/docs/api/remote.md index 0bed3ad..7f1c7f0 100644 --- a/docs/api/remote.md +++ b/docs/api/remote.md @@ -140,7 +140,26 @@ The `remote` module has the following methods: * `module` String -Returns `any` - The object returned by `require(module)` in the main process. +Returns `any` - The object returned by `require(module)` in the main process. Modules specified by their relative path will resolve relative to the entrypoint of the main process. + +e.g. + +```js +// main process: main/index.js +const { app, ipcMain } = require('electron') +app.on('ready', () => { +//... +``` + +```js +// some relative module: main/foo.js +module.exports = 'bar' +``` + +```js +// renderer process: renderer/index.js +const foo = require('electron').remote.require('./foo') // bar +``` ### `remote.getCurrentWindow()` -- 2.7.4