So here's the situation:
- I have an electron/angular JS app that is built for Windows, Linux, and Mac
- The app changes its behavior slightly when running on Linux; it needs a native node library, but only when running on Linux.
- This native node library is only able to build on Linux. There's code in my electron app's main.ts file to conditionally import this library when running on Linux.
- This native node library has typescript types bundled with it
- I am the maintainer of this native node library, so I can change it as needed.
- I still need this app to build on any platform. I need my Windows/Mac developers to be able to build and run this application on their machine, even though when they run it, the app won't dynamically load this library.
Does anyone have pointers on how to get all of this set up?
Here's what I've tried:
- Use some sort of tool to only
npm installthe library when building on a Linux machine. This doesn't work, because the Angular app still imports types from the library in several places, so the build fails on Mac/Windows if the library isn't installed. - Include the library as normal in package.json. This doesn't work because the build then fails on Mac/Windows. Even though the app doesn't use the library when it's installed,
npm installstill tries to build the native library on any platform and that doesn't work. - Include my library as an "optionalDependency". I thought this one would work, but electron still tried to rebuild the library on every platform, which didn't work.
So I'm stuck, and that's why I'm here. Has anyone else had to include a platform-specific native node library in their "Multiplatform" electron app? If so, how'd you do it?