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

如何在less里面引用背景图片,我利用相对路径,但是打包的时候,找不到图片 #1

Open
hjx5309 opened this issue Oct 12, 2018 · 3 comments

Comments

@hjx5309
Copy link

hjx5309 commented Oct 12, 2018

No description provided.

@youka2012
Copy link

youka2012 commented Jan 12, 2019

你要让webpack通过你的路径找到图片;我图片放在在src目录assets/里,webpack注意url-loader的name和publicPath,这关系到生产环境里图片路径查找,相关代码如下:
{
test: /.(jpe?g|png|gif|bmp|ico)(?.*)?$/i,
loader: "url-loader?limit=8048&name=assets/url-img/[name].[hash:5].[ext]&publicPath=../../",
},
.login-box {
background: url("../../assets/url-img/login/login_bg.png") no-repeat;
text-align: center;
height: 100%;
}
完整项目可参考
https://github.com/youka2012/react-antd-webpack-ie8
这个项目初期也是基于HeavenSky的项目构建的

@youka2012
Copy link

另外,注意url-loader版本,我是换到0.5.6才舒服起来。。。

@HeavenSky
Copy link
Owner

HeavenSky commented May 2, 2019

不好意思,工作巨忙,一直没看,没想到还是有人看的。
less-loader 我理解是需要配置下的option配置,你看看是否需要加上。

		relativeUrls: false, // 是否开启相对路径
		javascriptEnabled: true, // 不设置似乎会报错

哎,改用MAC就不知道咋维护了,如果有问题,建议把所有依赖锁版本,就是把这个三角^去掉。

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

3 participants