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

webpack打包html中图片的问题 #7

Open
ckinmind opened this issue Feb 8, 2017 · 1 comment
Open

webpack打包html中图片的问题 #7

ckinmind opened this issue Feb 8, 2017 · 1 comment

Comments

@ckinmind
Copy link
Owner

ckinmind commented Feb 8, 2017

发现webpack没法直接处理html中引入到图片问题,比如下面这样

 <div className="apple"><img src="../images/apple.png" alt=""/></div>

上面这个图片对应的路径是开发环境下的地址,但是打包后的资源文件是assets, webpack并不会这样引入的图片,要解决这个问题有几种方式

  1. 更改引入方式,使用css background的方式引入
  2. 修改这里的src地址,改成相对于打包后的地址,然后将图片拷贝到assets目录,比如src="assets/apple.png"
  3. 使用require的方式加载图片,在gallery-by-react中使用过这样干方式
  4. 百度webpack 图片路径
@ckinmind
Copy link
Owner Author

ckinmind commented Feb 8, 2017

第三方式这样写

  <div className="apple"><img src={require('../images/apple.png')} alt=""/></div>

webpack打包的时候回去找这个图片,并且回应用url-loader的规则,小于8kb转base64

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant