在 js 中通过使用 import 引入图片,如果图片不被转成 base64,会在打包过程中将图片转移至 dist/static 目录下。
import titleImg from './images/title.png';
export default class Login extends Component {
render() {
return (<img src={titleImg} alt="标题" />)
}
}
但是此时的图片路径不应该是 /static/title.ce51fdaf.png
,而应该是 ./static/title.ce51fdaf.png
。
网站路径是
|——index.html
|——static
|——|
|——|——title.ce51fdaf.png
这应该是在打包配置中可以修改的吧?
webpack的output下的publicPath配置成./xx即可
https://github.com/sorrycc/ro...