简体   繁体   English

使用电子打包程序构建应用后,javascript无法找到图像

[英]After building app using electron-packager the javascript can't find images

The app works fine when I run it via $npm start . 当我通过$npm start运行该应用程序时,它运行良好。 After I have built the app using electron-packager the javascript within the built app can't find assets in the images directory. 在使用electronic-packager构建应用程序之后,构建的应用程序中的javascript在images目录中找不到资产。

Example: I define the app icon in my main.js var mb = menubar({width: 370, height: 210, preloadWindow:true, icon: 'img/icon/icon.png'}); 示例:我在main.js中定义应用程序图标var mb = menubar({width: 370, height: 210, preloadWindow:true, icon: 'img/icon/icon.png'}); It gives the error Uncaught Error: ENOENT: no such file or directory, open 'img/icon/icon.png' . 它给出错误Uncaught Error: ENOENT: no such file or directory, open 'img/icon/icon.png'

If I load the image in the HTML it works fine. 如果我将图像加载到HTML中,则效果很好。

打包分发后,相对路径不再起作用,您必须使用__dirname创建路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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