Search code examples
javascriptelectronelectron-packager

Electron Packager - working with relative paths


I was wondering how I would deal with relative paths within my application when using electron packager.

In my app source folder I have some json files and other files that I reference. When packaging, electron-packager creates the \resources\app directory and places all these files into that directory. This means that any relative paths I'm using during development fail in the packaged app.

I tried pre-emtping this by creating the \resources\app folder in my source directory hoping the packager would notice them and just move them directly but it created \resources\app\resources\app instead.


Solution

  • I have had success using __dirname along with upath to build paths to assets.

    I like upath rather than path because it has a toUnix method which "replaces the windows \ with the unix / in all string params & results."

    var imgPath = upath.toUnix(upath.join(__dirname, "assets","welcome.png"));