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

静态文件在改 base 之后,路径错误 #128

Closed
ottocsb opened this issue Nov 30, 2023 · 4 comments
Closed

静态文件在改 base 之后,路径错误 #128

ottocsb opened this issue Nov 30, 2023 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@ottocsb
Copy link
Contributor

ottocsb commented Nov 30, 2023

信息

nodejs 版本

v18


包管理器及其版本

pnpm


系统

win10



bug

描述

佬,关于vite.config中配置了base上下文后,该如何引用public目录中的静态资源呢,在引用处加上base内容,dev环境可以正常展示,打包时提示错误。
如果不加base内容,则无法加载。

预期结果

正常加载。


最小测试仓库

最小复现环境就是base配置任意值后,notFound页资源无法加载。

@ottocsb
Copy link
Contributor Author

ottocsb commented Nov 30, 2023

目前改成: import notFound form "/public/notFount/xxx.svg",但引用图片的组件都要加几个import略显繁琐

@markthree
Copy link
Member

@ottocsb 靓仔,你好,我将稍后查看这个问题

@markthree markthree changed the title 关于vite.config 静态文件在改 base 之后,路径错误 Dec 1, 2023
@markthree markthree self-assigned this Dec 1, 2023
@markthree markthree added the bug Something isn't working label Dec 1, 2023
@markthree
Copy link
Member

@ottocsb 靓仔你好,已解决 -> 148d9204

通过这个方案,我们可以在任何位置使用 safeResolve('你的路径') 来做到 base 安全解析

@markthree
Copy link
Member

@ottocsb 具体可见 -> base 安全的路径解析

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

2 participants