医生sass loader
说:"If you're just generating CSS without passing it to the css-loader, it must be relative to your web root"
。所以我照它说的做了,我有我index.html
的project root
,然后我试图image
从我的scss
文件中加载一个。现在我有 2 个错误:1)来自Chrome's console
: Cannot find module "./img/header.jpg"
。2)从我的terminal
:
ERROR in ./~/css-loader!./~/sass-loader!./~/resolve-url-loader!./public/css/header.scss
Module not found: Error: Cannot resolve 'file' or 'directory' ./img/header.jpg in C:\Web-Development\React\Portfolio\public\css
@ ./~/css-loader!./~/sass-loader!./~/resolve-url-loader!./public/css/header.scss 6:64-91
webpack.config.js
module.exports = {
entry: './main.jsx',
output: {
filename: './public/js/build/bundle.js'
},
module: {
loaders: [
{
test: /\.jsx?$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel',
query: {
presets: ['react', 'es2015']
}
},
{
test: /\.scss$/,
loaders: ["style", "css", "sass", "resolve-url"]
},
{
test: /\.jpg$/,
loader: "file?name=[path][name].[ext]"
}
]
}
};
如果我看到我的代码,我可以清楚地看到我的 css 存在于内部<head>
,因此我已将图像的路径指向我的根目录,如文档所述,但仍然无法修复它。
更新:
我已经安装file-loader
并按照说明进行操作,现在我在控制台中收到此错误:GET http://localhost:3000/public/img/header.jpg 404 (Not Found) - jquery.js:9119