umi-server
umi-server copied to clipboard
图片资源的publicPath引用错误,显示undefined
What happens?
eggjs的例子,
在web/layouts/index 引入的图片无法显示, web/pages/home/index 下可以。
Mini Showcase Repository(REQUIRED)
Provide a mini GitHub repository which can reproduce the issue. Use
yarn create umi
then upload to your GitHub
How To Reproduce
Steps to reproduce the behavior:
-
在app/web下添加目录assets,放入图片logo.png
-
app/web/layouts/index
import logo from '@/assets/logo.png
...
...
...
render() {
<div className={classnames('layout', className)} >
<img src={logoPng} alt=""/>
<div>{this.props.children}</div>
</div>
}
- 结果图片的publicPatch显示undefined
<img src="undefinedstatic/logo.1ba85346.png" alt="">
Expected behavior
- 希望能够像在pages/home/index 中引入logo.png一样,显示正确的 publicPath: http://localhost:8000
Context
- Umi Version:
- Node Version:
- Platform:
我测试了下,未发现你说的问题,能否提供可复现的最小仓库,我看下,如果是图片的话,最好是不要放到项目里,可以把图片已经build好的文件都放到cdn上,这样不会占用服务器资源,服务器带宽只用来renderhtml,这样会稳定些。
我也遇到过,页面刚打开时会出现这样的情况,完全加载完后publicPath就会正常