Please take a look at the folder structures below:
src)â–¾ app/
â–¸ node_modules/
â–¸ out/
â–¸ workers/
package.json
â–¾ app.asar/
â–¸ node_modules/
â–¸ out/
package.json
â–¾ app/
â–¸ workers/
I'm trying to find a good way to work with external files. Due to our project's needs, we have to fork some processes from workers folder. I used extraResouces to get rid of worker folder and I got a problem since the path of worker folder is changed in the build. For instance, if I want to require blahblah-modules, I have to declare the path differently for each environment: blahblah-modules (development) and ../../app.asar/node_modules/blahblah-modules (build). I would like to ask for an advice to improve this silly path.
To be clear — require from worker code, right?
Possible approach — https://github.com/electron-userland/electron-builder/wiki/Loading-App-Dependencies-Manually (about dev mode, but you can add node module search path in production as well.
@develar Thanks a lot. That seems what I'm looking for.
Probably, if you can provide sample app, I will try find free time to play with it and simplify somehow.
Maybe, electron supports this search path if your worker will use asar.unpack. I am sorry, but without sample app I will not investigate it further.
@develar That's surprising when I tried to make a sample app. I can fork the worker with the path like electron-sample.app/Contents/Resources/app.asar/workers/text-generator. Regarding this I never thought that it could work. So I don't need any workaround so far.
Most helpful comment
@develar That's surprising when I tried to make a sample app. I can fork the worker with the path like
electron-sample.app/Contents/Resources/app.asar/workers/text-generator. Regarding this I never thought that it could work. So I don't need any workaround so far.