简体   繁体   English

电子打包机-使用相对路径

[英]Electron Packager - working with relative paths

I was wondering how I would deal with relative paths within my application when using electron packager. 我想知道使用电子封装程序时如何处理应用程序中的相对路径。

In my app source folder I have some json files and other files that I reference. 在我的应用程序源文件夹中,我有一些json文件和其他引用的文件。 When packaging, electron-packager creates the \\resources\\app directory and places all these files into that directory. 打包时,electron-packager会创建\\ resources \\ app目录,并将所有这些文件放入该目录。 This means that any relative paths I'm using during development fail in the packaged app. 这意味着我在开发过程中使用的任何相对路径在打包的应用程序中均失败。

I tried pre-emtping this by creating the \\resources\\app folder in my source directory hoping the packager would notice them and just move them directly but it created \\resources\\app\\resources\\app instead. 我尝试通过在源目录中创建\\ resources \\ app文件夹来进行预嵌入,希望打包程序会注意到它们并直接将它们移动,但是它改为创建了\\ resources \\ app \\ resources \\ app。

I have had success using __dirname along with upath to build paths to assets. 我已经成功地使用__dirnameupath来建立资产的路径。

I like upath rather than path because it has a toUnix method which "replaces the windows \\ with the unix / in all string params & results." 我喜欢upath而不是path因为它具有toUnix方法,该方法“在所有字符串参数和结果中用unix /替换windows \\”。

var imgPath = upath.toUnix(upath.join(__dirname, "assets","welcome.png")); 

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

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