How to write an Electron plugin? #1748
Replies: 10 comments 7 replies
-
+1 is there any way we could get a bare bones guide on creating a bridge between an electron app and capacitor |
Beta Was this translation helpful? Give feedback.
-
+1 Would be great to have an update regarding this! Especially if one would interact with desktop hardware. |
Beta Was this translation helpful? Give feedback.
-
Yep would be great. Have a capacitor wifi plugin and would like to extend it with electron support. Also If I know how to inckude electron I would create a file server plugin. |
Beta Was this translation helpful? Give feedback.
-
Same, it seems easy but I'm receiving errors while using registerElectronPlugin, at least an example would be nice. |
Beta Was this translation helpful? Give feedback.
-
+1 It has been almost a year after that answer has been posted |
Beta Was this translation helpful? Give feedback.
-
+1, no idea. |
Beta Was this translation helpful? Give feedback.
-
Ok, I think I sort of got it... 1.: 2.: 3.: import nodeResolve from '@rollup/plugin-node-resolve';
export default {
input: 'dist/esm/electron.js',
output: {
file: 'dist/electron-bridge.js',
format: 'iife',
name: 'capacitorPlugin',
sourcemap: true
},
plugins: [
nodeResolve()
]
}; 4.: You should now have your plugin under dist/esm/index.js and a electron-bridge.js file in dist/ 5.: webPreferences: {
nodeIntegration: true,
preload: path.join(__dirname, 'preload.js')
} 6.: require('@capacitor/electron/dist/electron-bridge');
require('your-awesome-plugin/dist/electron-bridge'); This will keep your plugin clean of any electron/nodejs code, so you should be able to use any existing webpack / whatever config insider your app. All electron code and imports are only inside electron-bridge.js rollup compiled and the electron.js inside dist/esm. Since the plugins index.js does no export them, your build systems should ignore them as well. When running electron, the electron-bridge package gets preloaded and you should have all you native electron stuff. This seems to be roughly how capacitor does it under the hood, as far as I can tell and it works quite well for me. |
Beta Was this translation helpful? Give feedback.
-
@IT-MikeS -- @kensodemann recommended I contact you regarding creating custom plugins for Electron. Would you be willing to provide a "hello world" (or maybe the "Echo" example from the docs) example of how someone would write an Electron plugin? Thanks! |
Beta Was this translation helpful? Give feedback.
-
Just as a little update, There is a preview version of the next electron platform version up on the new Capacitor Community Org. at: That version has a new pattern for plugins for electron and a document on how to start making them. |
Beta Was this translation helpful? Give feedback.
-
Hey everyone, now that capacitor 2.3 has released, it brings support for community platforms via CLI. I have updated the electron platform (https://github.com/capacitor-community/electron) with instructions on how to use it with the new CLI features and there is also now a plugin guide on that repo too. 🎉 |
Beta Was this translation helpful? Give feedback.
-
I'm trying to write an Electron plugin, but I found almost no useful information in the docs. I started by making a
WebPlugin
as suggested in #1281. I'm still struggling to finish and deploy this plugin, and I have a few more questions that haven't been covered yet.Sorry for all the questions, but I'm in the process of porting an Electron/Ionic app to Capacitor, and these are all issues I've run into.
Beta Was this translation helpful? Give feedback.
All reactions