1

Long story short:

I need to copy some files/directories over from my src folder to my dist/resources folder. Is there any way I can 'automatically' copy these files/folders over during packaging? I am using Electron-packager.


Long story:

I have a couple of folders containing JSON files that need to be read and copied over to a certain user directory. These are all done when I mount a certain component.

I use readFileSync() and using path.resolve with __dirname - but this generates an error since my relative path is different when I am running the packaged app (inside dist folder). Error is it cannot find my JSON file in dist/resources/config/settings.json. Also tried to check content of my app.asar but can't seem to find it there.

So my working workaround is to copy the directory/files over from my src folder to my dist/resources folder.

But this is kind of hacky and prone to forgetting. Is there any way I can 'automatically' copy these files/folders over during packaging?

kzaiwo
  • 1,558
  • 1
  • 16
  • 45

1 Answers1

0

I've seen a lot of questions like this and I've never really understood them. Maybe your project structure is very different than mine (below)?

Everything that is within my "app" directory is included by electron-packager (or electron-builder – I use both) and so it's all available when the app i packaged. In my case I have some Excel templates which the user can opt to save to disk but I could just as well create a directory and copy them there at first launch (haven't tried this but assuming permissions are ok I don't doubt that it will work). Maybe that is less "clean" than having a separate resources folder?

That said, I have seen this: Electron - How to add external files?


enter image description here

spring
  • 18,009
  • 15
  • 80
  • 160