Rails 6-似乎无法从我的CSS加载图像

问题描述 投票:0回答:1

我有这个项目,我想使用我在app / javascript / images中拥有的某个背景图片(我所有的图片都在那里)。当我在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
    └── ...

application.js:

const images = require.context('../images', true);
const imagePath = (name) => images(name, true);
css ruby-on-rails asset-pipeline
1个回答
0
投票

因此,基本上,我将图像切换到资产管道并使用了它:

asset-url('photo.jpg')

仅此而已。

© www.soinside.com 2019 - 2024. All rights reserved.