当我尝试构建 萨斯使用 webpack 文件,我收到以下错误:
Module not found: Error:Cannot resolve module 'file-loader'
请注意,此问题仅在我尝试使用相对路径加载背景图像时发生。
这工作正常:
background:url(http://localhost:8080/images/magnifier.png);
这导致了问题:
background:url(../images/magnifier.png);
这是我的项目结构
这是我的 webpack 文件:
var path = require('path');
module.exports = {
entry: {
build: [
'./scripts/app.jsx',
'webpack-dev-server/client?http://localhost:8080',
'webpack/hot/only-dev-server'
]
},
output: {
path: path.join(__dirname, 'public'),
publicPath: 'http://localhost:8080/',
filename: 'public/[name].js'
},
module: {
loaders: [
{test: /\.jsx?$/, loaders: ['react-hot', 'babel?stage=0'], exclude: /node_modules/},
{test: /\.scss$/, loaders: ['style', 'css', 'sass']},
{test: /\.(png|jpg)$/, loader: 'file-loader'},
{test: /\.(ttf|eot|svg|woff(2)?)(\?[a-z0-9]+)?$/, loader: 'file-loader'}
]
},
resolve: {
extensions: ['', '.js', '.jsx', '.scss', '.eot', '.ttf', '.svg', '.woff'],
modulesDirectories: ['node_modules', 'scripts', 'images', 'fonts']
}
};
最佳答案
正如@silvenon 在他的评论中所说:
Do you have file-loader installed?
是的文件加载器 已安装但损坏,我的问题已通过重新安装解决。
npm install --save-dev file-loader
关于sass - Webpack:无法解析模块 'file-loader',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34352929/