[英]Electron-Builder include external folder
I am building multiple electron apps and have one directory for common pictures and files.我正在构建多个 electron 应用程序,并且有一个用于常见图片和文件的目录。 I would like to include them when building each app with electron-builder.
我想在使用 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 键,但使用此配置文件似乎不起作用:
"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">
.我正在尝试使用此 HTML 代码
<link rel="stylesheet" href="../common/css/master.css">
访问公共目录。 It works when starting it with electron.
使用
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.用于调试和开发,但是在使用 electron-builder 构建时,它似乎没有打包公共目录并在控制台中抛出“找不到文件”。
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然后你可以在你的渲染器的任何地方使用这个
appResourcePath
例如
<img src=path.join(appResourcePath, 'img', 'background.png')>
Then this will be working in any environment.那么这将在任何环境中工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.