我遇到了编译SASS代码的问题。
我想使用背景图片,但是当我尝试这样做时,所有的CSS都停止工作了。
我的SASS文件如下所示:
@import "~bootstrap/scss/bootstrap";
@import "constants";
#crossroad {
position:relative;
background-image: url("../assets/bg.jpg");
}
我的Webpack配置文件
const path = require('path');
module.exports = {
entry: './src/app.js',
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist')
},
mode: "development",
module: {
rules: [
{
test: /\.(scss|png|jpg)$/,
use: [
{
// Adds CSS to the DOM by injecting a `<style>` tag
loader: 'style-loader'
},
{
// Interprets `@import` and `url()` like `import/require()` and will resolve them
loader: 'css-loader'
},
{
// Loader for webpack to process CSS with PostCSS
loader: 'postcss-loader',
options: {
plugins: function () {
return [
require('autoprefixer')
];
}
}
},
{
// Loads a SASS/SCSS file and compiles it to CSS
loader: 'resolve-url-loader'
},
{
// Loads a SASS/SCSS file and compiles it to CSS
loader: 'sass-loader'
}
]
}
]
}
};
错误信息:
ERROR in ./src/assets/bg.jpg (./node_modules/css-loader/dist/cjs.js!./node_modules/resolve-url-loader!./node_modules/postcss-loader/src??ref--4-2!./node_modules/sass-loader/dist/cjs.js!./src/assets/bg.jpg)
模块构建失败 (来自 ./node_modules/sass-loader/dist/cjs.js):
SassError: 在 /Users/adrianmindek/Code/PersonalPage/src/assets/bg.jpg 的第1行中,"����" 后的CSS无效:预期"{",但是得到了""
����
^
@ ./src/assets/bg.jpg 2:26-236
@ ./node_modules/css-loader/dist/cjs.js!./node_modules/resolve-url-loader!./node_modules/postcss-loader/src??ref--4-2!./node_modules/sass-loader/dist/cjs.js!./src/scss/app.scss
@ ./src/scss/app.scss
@ ./src/app.js
我尝试将 resolve-url-loader
添加到我的 webpack 配置文件中,但是没有任何变化。