ng build --base-href ="/.../"; --deploy-url =“"/.../"CSS背景图片不起作用 [英] ng build --base-href="/.../" --deploy-url="/.../" css background image not working

查看:452
本文介绍了ng build --base-href ="/.../"; --deploy-url =“"/.../"CSS背景图片不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

"@ angular/core":〜8.0.0",

"@angular/core": "~8.0.0",

带scss样式选项的脚手架Angular 8项目

scaffold angular 8 project with scss style option

我在组件scss文件中具有如下所述的代码

i have code for as mentioned below in component scss file

背景:url("/assets/images/vector-icon.png")不重复25%;

background: url("/assets/images/vector-icon.png") no-repeat 25%;

使用命令最终完成

ng build --prod --base-href="/website/" --deploy-url="/website/"

在子文件夹中放入构建 根/网络端

put build at sub folder root/webside

除背景图片路径之外的所有其他东西

everything working fine except background image path

我已经尝试通过ip/website/assets/images/vector-icon.png 到那时我就能得到图像了.

i have tried by ip/website/assets/images/vector-icon.png at that point i am able to get image.

如果我不更改每个CSS文件的路径怎么办?

What if i don't wont to change the path at every css file.

任何帮助将不胜感激.预先感谢

any help would be appreciated. thanks in advance

推荐答案

解决方案是将"rebaseRootRelativeCssUrls":true放入angular.json文件中.

The solution is to put "rebaseRootRelativeCssUrls": true in the angular.json file.

资产前的/正确.(url(/assets/img ...))

The / before assets is correct.( url(/assets/img...) )

 "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
           ...
           "rebaseRootRelativeCssUrls": true

这篇关于ng build --base-href ="/.../"; --deploy-url =“"/.../"CSS背景图片不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆