简体   繁体   中英

Electron-Builder include external folder

I am building multiple electron apps and have one directory for common pictures and files. I would like to include them when building each app with electron-builder. The docs recommended -if I understood correctly- adding the path to the build > files key but it doesn't seem to work using this config file:

"build":{
    "files": [
        "**/*",
        "../common/img/*"
    ]
}

My directory structure is as follows:

|git_folder
|-- electronapp1
|---- package.json
|-- electronapp2
|---- package.json
|-- common
|---- img
|---- js
|---- css

I am trying to access the common directories with ie this HTML code <link rel="stylesheet" href="../common/css/master.css"> . It works when starting it with electron. for debugging and developing, but when building with electron-builder, it doesn't seem to pack the common directories and throws "File not found" in the console.

In your configuration,

"extraResources": [
    {
        "from": "../common",
        "to": "common"
    }
],
"files": [
  "**/*"
],

So if I were you I'll configure like this

const path = require("path");
const appPath = __dirname;
const appResourcePath = path.join(appPath, "..", "common")

module.exports = {
  appPath,
  appResourcePath
};

Then you can use this appResourcePath anywhere at your renderer Such as

<img src=path.join(appResourcePath, 'img', 'background.png')>

Then this will be working in any environment.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM