SASS相对网址配置错误

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

我正在从事React项目,并且在指向带有相对路径的scss文件中的图像资产时遇到问题。通常,相对路径在本地工作,但是在部署到github页面后,到图像资产的路由缺少github repo name部分。我不知道这是webpack配置问题,还是写错了相对路径。

这是我的文件夹结构

├───config
│   └───jest
├───public
│   └───assets
│       ├───css
│       ├───fonts
│       ├───images
│       │   ├───background
│       │   ├───icons
│       │   ├───illustration
│       │   ├───logo
│       │   └───projects
│       │       ├───one
│       │       └───two
│       ├───js
│       └───scss
│           ├───blog
│           ├───common
│           ├───default
│           ├───elements
│           ├───header
│           └───template
├───scripts
└───src
    ├───component
    │   ├───common
    │   ├───footer
    │   ├───header
    │   └───slider
    ├───elements
    │   ├───blog
    │   ├───common
    │   ├───portfolio
    │   ├───projects
    │   └───tab
    └───home

scss文件中定义的示例URL路径:

.big-center-circle {
    background: url("/assets/images/background/circle-1.svg") no-repeat center top,
}

部署中的最终路由

https://username.github.io/assets/images/background/circle-1.svg

部署中所需的路由

https://username.github.io/repository-name/assets/images/background/circle-1.svg

我使用react-router-dom进行路由,并且相对路径在jsx文件中正常工作。我只有SCSS样式表中的网址有问题。

reactjs sass routing
1个回答
0
投票

已解决。我发现资产的url应该定义放置在scss文件夹中的主src文件的相对路径。

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