0
我正在本地加載圖像,圖像文件位於jsx文件的同一文件夾中。該webpack.config.js是看起來是這樣的:Webpack img-loader無法加載圖像
path = require('path');
module.exports = {
context: __dirname,
entry: "./app/entry.jsx,
output: {
path: path.join(__dirname, 'lib'),
filename: "bundle.js",
devtoolModuleFilenameTemplate: '[resourcePath]',
devtoolFallbackModuleFilenameTemplate: '[resourcePath]?[hash]'
},
module: {
loaders: [
{
test: /\.jsx?$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel',
query: {
presets: ['react']
}
},
{
test: /\.css$/,
loader: "style-loader!css-loader?root=."
},
{
test: /\.(jpe?g|png|gif|svg)$/i,
loader: 'url?limit=10000!img?progressive=true'
}
]
},
devtool: 'source-map',
resolve: {
extensions: ["", ".js", ".jsx" ]
}
};
和JSX是這樣
var loadingImg = require('url!img!./loading.gif');
錯誤顯示在控制檯:
ERROR in Loader app/node_modules/url/url.js didn't return a function
@ app/components/session/login.jsx 5:17-49
我應該如何加載此圖片?
您不需要'require()'中定義的加載器。從文檔:「[在配置中指定加載程序是推薦的方法](https://webpack.github.io/docs/loaders.html)」 –