11

I have a file that i need compulsory to make my application work,i am able to use the file in development by specifying fixed path var path = process.cwd() + '/src/app/components/task/Scripts'; and the file name after that,but after packaging the app i want to move the file i need in extraResources folder in system from where i will be able to use it let path = pathPackage.join(process.resourcesPath, 'extraResources');,i am using electron-forge maker to produce a production build exe,how ever there is no extraResources folder created after installing the exe,i am specifying it in package.json file

"build": {
 "extraResources": [
   "./extraResources/**"
 ]
},

Can someone provide a solution for it,i have tested all examples but none of them worked

Martin
  • 111
  • 1
  • 4

1 Answers1

9

As it mentions in the documention (actual options documented here), you can add files using the extraResource option of the packagerConfig configuration.

extraResource extraResource: string | string[]

  • One or more files to be copied directly into the app's Contents/Resources directory for macOS target platforms, and the resources directory for other target platforms. The resources directory can be referenced in the packaged app via the process.resourcesPath value.

For example, in your package.json file:

 {
   "config": {
     "forge": {
       "packagerConfig": { 
         "extraResource": [
           "./src/extraResources/file.txt",
           "./src/extraResources/folder"
          ]
        }
      }
    }
  }

The files will be placed in the process.resourcesPath directory when running npm run package.

Chris Weber
  • 5,555
  • 8
  • 44
  • 52
WhatsMyPurpose
  • 143
  • 1
  • 6
  • Thanks @WhatsMyPurpose. This was more difficult to figure out then it should be b/c the google results are seemingly out of date. – Chris Weber Jul 01 '22 at 23:43
  • 1
    This worked, but only for the packaged app. `process.resourcesPath` resolved to something weird when running `electron-forge start`. I had to use __dirname, which points to the `.webpack/main` folder in both production and dev settings. I used `copy-webpack-plugin` to put files there. – RandomEngy Dec 30 '22 at 18:36
  • will this command copy the node_modules folder into the resources folder? Second will the paths break if I have development paths? https://stackoverflow.com/questions/76397570/expected-app-structure-and-pathing-problems-after-build-of-electron-project-usin – Gary Jun 04 '23 at 05:16