【发布时间】:2016-03-02 09:25:55
【问题描述】:
sass loader 文档说:"If you're just generating CSS without passing it to the css-loader, it must be relative to your web root"。
所以我照它说的做了,我的project root 中有我的index.html,然后我试图从我的scss 文件中加载一个image。
现在我有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
【问题讨论】:
-
问题可能出在 bower_components 目录上?我在这里遇到了类似的字体问题:stackoverflow.com/questions/33733370/…
-
我面临着类似的问题。我已经安装了 url-loader、file-loader 但仍然出现错误 localhost:8080/97e0c94dad5b497783b1400e27dfdcbb.jpg 404 (Not Found)
标签: javascript css node.js webpack sass-loader