npm 包中的 CSS 图像 url
我有一个在我的主要 webpack 构建应用程序中使用的包。在包中,我有一个组件及其相应的 .scss
文件。文件夹结构为:
component
|- assets
|- background-image.svg
component.tsx
component.scss
component.scss
尝试使用 background-image
,如下所示:
background: url('assets/bacgkround-image.svg')< /code>
这在故事书文件中运行良好,并且背景已正确加载。
但是,当我尝试将该组件包含在我的主 React 应用程序中时,构建失败并出现以下错误:
Module not found: Error: Can't resolve './assets/background-image.svg' in '<path-to-my-package-directory'
我很困惑。将相对 url 中的图像包含在 css 文件中的正确方法是什么?
I have a package that I am using in my main webpack-built app. In the package, I have a component with its corresponding .scss
file. The folder structure is:
component
|- assets
|- background-image.svg
component.tsx
component.scss
component.scss
is trying to use background-image
as such:
background: url('assets/bacgkround-image.svg')
This works fine in a storybook file and the background is loaded properly.
However, when I try to include the component in my main React app, the build fails with the following error:
Module not found: Error: Can't resolve './assets/background-image.svg' in '<path-to-my-package-directory'
I am confused. What is the right way to include the image from a relative url in a css file?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论