I think time has come to switch from AngularJS to version 2. While there are projects out there which are proof-of-concept that Angular 2 can run in Electron, I have an error which I have yet to find a solution for.
Note: I'm trying to access
electron module in renderer by using
ng build to compile my project.
I've made my project using two package.json structure like any other Electron app. I've successfully added Angular and ran it. So far so good. But then I've tried to
require('electron') in renderer and things fell apart. It seems to me that it has something to do with TypeScript compiling my app.
Haven't found it yet. Is it only problem on my machine? Is it problem in require? Anyhow, I'll update this post when I have working solution, but in the meantime, if anyone has any idea, feel free to drop a comment.
Update (31.10.2016): I've been reading a lot on this topic and here is my summary:
- Angular-cli has webpack, but is not configurable. ETA is somewhere in 2017.
- Electron projects built with webpack works. I've tried it on this project.
- Accessing node modules works for both webpack and angular-cli. Interestingly,
os.platform()on webpack is displaying 'darwin' while with angular-cli is 'browser'!
- Previous point leads me to think that angular-cli is missing configuration to recognise electron as a platform.
I managed to access electron API by adding following to
<script> var electron = require('electron'); </script>
Then in TS you can declare electron and access any method/property:
declare var electron: any;
This is very hackish solution and doesn't solve problem of
os.platform() being browser.
Finally, I've added Angular-CLI to post title, so that it is apparent that I'm describing problem with it. Until we have some system with addons or configuration of Webpack there is no point in spending more time on this issue.