我正在做一个带有Webpack设置的React,并且正在努力做应该看起来很简单的事情。我希望webpack包含图像,并像使用gulp一样将其最小化,但我无法弄清楚。我只希望能够像这样在我的CSS中链接图像:
/* ./src/img/background.jpg */
body { background: url('./img/background.jpg'); }
我所有的css / js / img文件夹都放在src文件夹中。Webpack输出到dist文件夹,但是我不知道如何在那里获取图像。
这是我的webpack设置:
var path = require('path');
var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
devtool: 'cheap-eval-source-map',
entry: [
'webpack-dev-server/client?http://localhost:8080',
'webpack/hot/dev-server',
'./src/index.js'
],
output: {
path: path.join(__dirname, 'dist'),
// publicPath: './dist',
filename: 'bundle.js'
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new HtmlWebpackPlugin({
template: './src/index.html'
})
],
module: {
loaders: [{
exclude: /node_modules/,
test: /\.js?$/,
loader: 'babel'
}, {
test: /\.scss$/,
loader: 'style!css!sass'
}, {
test: /\.(png|jpg)$/,
loader: 'file-loader'
}]
},
devServer: {
historyApiFallback: true,
contentBase: './dist',
hot: true
}
};