sass loader
doc nói: "If you're just generating CSS without passing it to the css-loader, it must be relative to your web root"
. Vì vậy, tôi đã làm như nó nói, tôi có index.html
của tôi trong project root
của tôi, sau đó tôi đang cố gắng để tải một image
từ tập tin scss
của tôi. Bây giờ tôi có 2 lỗi: 1) từ Chrome's console
: Cannot find module "./img/header.jpg"
. 2) từ terminal
tôi:Webpack - bộ nạp sass không thể tìm thấy hình ảnh
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]"
}
]
}
};
Nếu tôi thấy mã của tôi, tôi có thể thấy rõ rằng css tôi sống bên <head>
vì vậy tôi đã chỉ hình ảnh của tôi đường dẫn đến gốc của tôi, như tài liệu nói, nhưng vẫn không thể sửa chữa nó.
UPDATE: Tôi đã cài đặt file-loader
và theo các hướng dẫn, bây giờ tôi nhận được lỗi này trong giao diện điều khiển: GET http://localhost:3000/public/img/header.jpg 404 (Not Found) - jquery.js:9119
Sự cố có thể xảy ra với thư mục bower_components? Tôi gặp sự cố tương tự ở đây với phông chữ: http://stackoverflow.com/questions/33733370/webpack-cannot-load-fonts-from-bower-using-css-scss – Zorgatone