0

我无法在 scss 中将图像作为背景图像插入。我的主题中有图像:custom/plugins/MyTheme/src/Resources/app/storefront/src/assets/img/my-image.png 并且我正在尝试在 scss 文件中使用此图像。当我使用时,./psh.phar storefront:build我可以在店面中看到图像,但是当我使用时./psh.phar storefront:hot-proxy出现错误:

This relative module was not found: * ../assets/img/my-image.png in ./node_modules/css-loader/dist/cjs.js??ref--8-1!./node_modules/postcss-loader/src??ref--8-2!./node_modules/sass-loader/lib/loader.js??ref--8-3!/app/var/theme-entry.scss

在 scss 我使用路径:background-image: url("../assets/img/my-image.png");

如何在scss中正确添加文件?

4

2 回答 2

0

您需要将文件相对于主题 css,然后直接从那里引用。像“图像/abc.jpg”。

于 2020-09-01T09:05:32.573 回答
0

我认为您应该从论坛 https://forum.shopware.com/discussion/70245/plugin-assets-in-scss-verlinken尝试此解决方案

在我的主题中,我创建了这个变量并像这样使用它

$bundle-path: '../../..//bundles/mybundle/';
$icon-chevron-right: url($bundle-path + '/assets/icon/chevron-right-xs.svg');

或者您可以像这样对其进行硬编码

$icon-chevron-right: url(/bundles/mytheme/assets/icon/chevron-right-xs.svg) !default;
于 2020-11-27T05:19:23.017 回答