css - 如何在 Next JS 中设置 CSS/SCSS 背景图像属性?
问题描述
我正在使用 React 和 Next JS 开发一个项目,这是文件结构的一瞥:
// other root folders...
L pages
L public
L src
L assets
L image.svg // this is the image that I wanted to turn into a background of an element
L components
L styles
L divider.module.scss // this is where I've added the background-image property
我已经使用import image from '[file path]'
官方文档中的自定义 Web 包配置使用具有各种扩展名的语法成功导入了图像。next.config.js 包含以下内容:
module.exports = {
webpack: (config) => {
config.module.rules.push({
test: /\.(png|jpe?g|gif|svg)$/i,
loader: 'file-loader',
options: {
name: '[name]_[hash].[ext]',
publicPath: `/_next/static/assets`,
outputPath: 'static/assets',
},
});
return config;
},
};
然而,问题是使用 CSS/SCSS 加载的图像似乎会引发这个特定的错误:XML Parsing Error: syntax error export default "[file path]";
. 谁能详细说明我做错了什么?谢谢你。
解决方案
推荐阅读
- python-3.x - 训练后损失和准确率保持不变
- redis - 如何在 Redis 中设置/重置/更改流顶部项目 ID?
- flutter - Flutter - 如何在一行中显示文本和图标?
- html - 如何水平对齐伪元素与元素及其容器
- java - 我们如何在 Sailpoint IIQ 中设置日期范围
- unit-testing - NestJS Jest 测试期待然后最终捕获
- python - 如果行的内容包含特定的子字符串,如何排除 Daraframe 中的列?
- google-classroom - 课堂主题 API 给了我帐户受限错误
- python - 使用 Matplolib 将绘图保存在图像文件中
- react-native - 同时使用抽屉导航和堆栈导航