How to add extra resources files in production in electron using electron-forge

Viewed 929

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

1 Answers

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.

Related