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

1

12

I have a file that I need 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 into the extraResources folder in the 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. However there is no extraResources folder created after installing the exe.

I am specifying it in the package.json file

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

Can someone provide a solution for this? I have tested all examples but none of them worked.

Slivovitz answered 6/4, 2021 at 14:9 Comment(1)
Did you find any fix for this ? I'm running into the same thingDraconic
R
13

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.

Rowlett answered 27/6, 2022 at 20:38 Comment(5)
Thanks @WhatsMyPurpose. This was more difficult to figure out then it should be b/c the google results are seemingly out of date.Lareelareena
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.Tesstessa
will this command copy the node_modules folder into the resources folder? Second will the paths break if I have development paths? #76398070Winstead
Dude thanks! Have been stuck on this all day. If anyone is using forge.config.js instead of package.json add packagerConfig: { asar: true, extraResource: ['./src/extraResources']}Disease
i have performed the above steps , i have node script inside extra resources, but at the runtime node modules not found that is required in script .Fink

© 2022 - 2024 — McMap. All rights reserved.