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

查看:45
本文介绍了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

推荐答案

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

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

assets 之前的/是正确的.( 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天全站免登陆