Electron - How to add external files?

前端 未结 4 1785
感动是毒
感动是毒 2020-12-05 05:42

I have an Electron app. I try to make the app open an .exe file. I created a directory in the root folder named lib and placed the .exe file there. In developme

4条回答
  •  离开以前
    2020-12-05 06:16

    Add the following code to package.json:

     "build": {
        "extraResources": [
          {
            "from": "./src/extraResources/",
            "to": "extraResources",
            "filter": [
              "**/*"
            ]
          }
        ]
      }
    

    Then, you can access the files using

    const configFile = path.join(path.dirname(__dirname), 'extraResources','config.json');
    

    I use the following folders structure which allows me to run the app any way.

    from project folder: node_modules\.bin\electron.cmd src\main\index.js

    from unpacked source dist\win-unpacked\app.exe check-for-update

    from installed folder C:\Users\user\AppData\Local\Programs\app\app.exe

    +-- dist
    |   +-- win-unpacked
    |      +-- resources
    |         +-- extraResources
    |            config.json
    +-- node_modules
    +-- src 
    |   +-- extraResources
    |      config.json
    |      someFile.js
    |   +-- main
    |      index.js
    |   +-- render
    |      index.js
    

提交回复
热议问题