javascript - Electron 在编译版本中不显示图像
问题描述
我正在尝试解决有关电子的问题。
它不显示来自 css 文件的任何图像,另一方面,它可以在以前的版本中正常显示,而无需编译应用程序。
我的项目是如何组织的。
main.js文件(我隐藏了一些无用的信息“宽度,高度......”)
function createWindow () {
win = new BrowserWindow({
//...
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
enableRemoteModule: true,
preload: path.join(__dirname, 'preload.js')
}
})
win.loadFile('index.html')
}
app.whenReady().then(() => {
createWindow()
})
index.html这里有我的样式文件,
<link rel="stylesheet" type="text/css" href="./css/styles.css">
在它的定义中,我们有:
.class{
background-image: url('file:///logos/logo_gc.png');}
preload.js (não há nada)
我测试了几种解决方案,例如:
我试图将导入放在所有可能的文件中,但什么也没有。
Version electron: 12.0.15
Compiler: electron-packager
Command: electron-packager 'path' --overwrite --asar --platform=win32 --arch=x64 --prune=true --out=release-builds --version-string.CompanyName=CE --version-string .FileDescription=CE --version-string.ProductName="Infosac"
解决方案
打包应用程序总是与文件路径混淆。
只需使用相对文件路径。
.class{
background-image: url('../logos/logo_gc.png');}
请记住,css
无论您的文件在哪里,这都是相对于您的文件路径html
的
推荐阅读
- ios - 如何在 Xcode 中使用 Cocoapods
- reactjs - react-designer 包的问题
- wordpress - .htaccess : 如何同时为 Symfony 和 Wordpress 重写 URL
- sql - 如何在 SQL 中使用 NOT IN () 返回空列
- encoding - 有没有办法在 Shell 中使用 base64 对 csv 中的多个列进行编码?
- reactjs - 无法从 gatsby-config.js 多个查询 GrahQL 读取 siteMetadata 对象 - Gatsby ReactJS
- python - 如何使用 python 控制桌面应用程序窗口
- java - 在 Java 中调用以获取书籍详细信息
- xcode - Xcode & Source Control - 如何重命名分支?
- user-interface - 如何在这个用 Go 编写的 GUI 中增加字体大小