[英]Rails 6 - Can't seem to load images from my css
我有這個項目,我想使用我在 app/javascript/images 中的某個背景圖像(我所有的圖像都在那里)。 當我在帶有 <%= image_pack_tag... %> 的 html 中使用它們時,它工作得很好。 但不知何故,當我嘗試這個時:
header.masthead {
padding-top: 10rem;
padding-bottom: calc(10rem - 4.5rem);
background-position: center;
background-repeat: no-repeat;
background-attachment: scroll;
background-size: cover;
background: linear-gradient(to bottom, rgba(92, 77, 66, 0.8) 0%, rgba(92, 77, 66, 0.8) 100%), image-url('images/singapore.jpg');
}
它根本不加載......當我檢查代碼時,它說找不到模塊。 我懷疑這是因為 webpack 沒有編譯來自 CSS 的圖像,盡管當我使用 image_pack_tags 時它來自我的 html 代碼。
Javascript 目錄:
├── stylesheets
│ ├── application.scss
│ └── style.scss
├── packs
│ ├── application.js
│ └── script.js
└── images
└── singapore.jpg
└── ...
應用程序.js:
const images = require.context('../images', true);
const imagePath = (name) => images(name, true);
所以基本上,我將我的圖像切換到資產管道並使用它:
asset-url('photo.jpg')
這就是全部。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.