I have a Webpack running with ReactJS, and I am attempting to grab an image and display it but getting an error: Uncaught Error: Cannot find module "../media/interiorTest.jpg"
And here is what I tried:
<div>
<img src={require("../media/interiorTest.jpg")}/>
</div>
And the directory tree is (I am trying to fetch interiorTest.jpg
from home-page.js
):
And my webpack.config.js
is:
const webpack = require('webpack');
const path = require('path');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const config = {
context: __dirname,
entry: './src/index.js',
output: {
path: __dirname,
filename: 'bundle.js'
},
module: {
loaders: [
{
exclude: /node_modules/,
test: /\.(js|jsx)$/,
loader: 'babel'
},
{
test: /\.scss$/,
loader: ExtractTextPlugin.extract('css!sass')
}
]
},
devServer: {
historyApiFallback: true,
contentBase: './'
},
plugins: [
new webpack.DefinePlugin({ 'process.env':{ 'NODE_ENV': JSON.stringify('production') } }),
new webpack.optimize.DedupePlugin(),
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.HotModuleReplacementPlugin(),
new webpack.optimize.UglifyJsPlugin({
compress: { warnings: false },
output: {comments: false },
mangle: false,
sourcemap: false,
minimize: true,
mangle: { except: ['$super', '$', 'exports', 'require', '$q', '$ocLazyLoad'] }
}),
new ExtractTextPlugin('src/public/stylesheets/app.css', {
allChunks: true
})
]
};
module.exports = config;