Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[🐞] After build, assets can not resolved correct. / 打包后,assets下资源路径不正确 #287

Closed
BloodlustLR opened this issue Oct 20, 2022 · 7 comments
Labels
bug Something isn't working

Comments

@BloodlustLR
Copy link

A{6`KF{8T$YI$XWQADEL_8C

img标签引用assets下的图片后,打包后安装图片都无法显示,路径指向dist而不是dist/assets导致无法读取
image

@BloodlustLR BloodlustLR added the bug Something isn't working label Oct 20, 2022
@realmx
Copy link

realmx commented Oct 24, 2022

我也遇到同样的错误

@wx980416
Copy link

不知道咋怎么解决啊

@ezesalmon
Copy link

ezesalmon commented Oct 27, 2022

I'm having the same issue!!!
I saw in older projects that I have with @vue/cli that static resource were load as:
src="app://./assets/my_logo.dcfdbf89.png"

Opening DevTools, I have changed the 'src' to app://./assets/..., but didn't work.
A second try was changing the 'src' into ./assets/my_logo.dcfdbf89.png and the image appeared!

Maybe the thing is to transform the output we're getting now, into something with like ./assets/... and not the full path, that actually does not exists due to ASAR packaging.
I had a quick look at the electron plugin API, but I didn't try anything

@caoxiemeihao
Copy link
Member

caoxiemeihao commented Oct 28, 2022

This may not be the right thing to do. 🤔
electron-vite/vite-plugin-electron@7e76ca6#diff-e195609aee645f6b35c36a455c23123070147a97f2be4d6a70b7708293f320f8L18
image


However, we can avoid this problem by configuring Vite.

export default defineConfig({
  build: {
+   assetsDir: '',
  },
})

@caoxiemeihao caoxiemeihao changed the title [Bug] 打包后,assets下资源路径不正确 [🐞] After build, assets can not resolved correct. / 打包后,assets下资源路径不正确 Oct 28, 2022
caoxiemeihao added a commit that referenced this issue Oct 28, 2022
@AslamHamdi
Copy link

You need to check the dist folder after release. Because the image will be read from there.

I add this in index.ts:

process.env.isDev = process.env.npm_node_execpath ? 'true' : 'false'

and then, use this to retrieve static files:

let path = process.env.isDev == 'true' ? '/src/Assets/Video/test.mp4' : __dirname + '/assets/Video/test.mp4'

the dist/ was generated from 'public' folder

@caoxiemeihao
Copy link
Member

caoxiemeihao commented Apr 11, 2023

virgoone pushed a commit to virgoone/electron-vite-vue that referenced this issue May 19, 2023
@ltcooooooo
Copy link

ltcooooooo commented Oct 20, 2023

我的打包之后也无法正常加载,后来发现是打包之后将图片转为了base64,在mate标签中添加
<meta http-equiv="Content-Security-Policy" content="default-src 'self' data:; script-src 'self'; style-src 'self' 'unsafe-inline'"/>
就解决了,可以参考一下

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

7 participants