Capacitor: How to make an Electron plugin the Capacitor way?

Created on 1 Mar 2019  路  3Comments  路  Source: ionic-team/capacitor

About a year ago, https://github.com/ionic-team/capacitor/commit/9f48abeb9d2e57e2afac1d2b5c03bea10181d6b1 included a note regarding Electron plugins:

We will have more info on building Electron plugins soon.

Has that info been made available anywhere? Is the strategy to follow what FileSystemPluginElectron does? Namely, implement a WebPlugin and just use whatever is needed from node.js like it does via require?

Does Capacitor provide any support for native-dependent modules that need separate builds between macOS/Windows/Linux?

Most helpful comment

@mlynch Any update on this ? Also interested in hearing the answers to @bcallaghan-fri questions

All 3 comments

Hey @natevwm, great question and we need to expand out those docs.

And yes that is the strategy: essentially build out a web plugin but then import and call registerElectronPlugin from @capacitor/electron.

We will be expanding those docs, but let us know how that goes!

I have a few more questions about building Electron plugins. These are all struggles I've had while building my own.

  1. Where do I call registerElectronPlugin? Should it be in the plugin's code? In the consumer's code? Should it be called in an Electron preload script, or in a regular renderer script?
  2. How do I import the registerElectronPlugin method? The main npm package is a CommonJS module that doesn't contain that function. It's buried deeper inside a separate, internal ES module.
  3. Are native npm modules (those containing platform-specific builds) supported in Capacitor plugins? If so, what is the process of building those (usually requires electron-rebuild)?
  4. How do I package and deploy an Electron plugin? Is it a separate package? Is it a folder within my Web plugin's package?
  5. When can I expect better documentation/templates/guides on building an Electron plugin?

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.

@mlynch Any update on this ? Also interested in hearing the answers to @bcallaghan-fri questions

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gnesher picture gnesher  路  3Comments

moberwasserlechner picture moberwasserlechner  路  3Comments

stripathix picture stripathix  路  3Comments

nicobytes picture nicobytes  路  3Comments

danielsogl picture danielsogl  路  3Comments