Answer the question
In order to leave comments, you need to log in
How to display an image in React + Redux (webpack)?
I'm trying to learn react + redux. I ran into a stupid problem, I've been googling for an hour and a half. There are a lot of similar problems, and the solutions described do not help.
So, I start the server on my localhost:3000 with the following structure:
Styles are connected in index.js like this: import './styles/compiled/app.css'
Styles have rules:
body {
background: url(/assets/back.jpg);
background-size: cover;
font-family: 'Open Sans', sans-serif;
}
body {
background: url(http://localhost:3000/assets/back.jpg);
background-size: cover;
font-family: 'Open Sans',sans-serif;
}
var path = require('path');
var webpack = require('webpack');
var autoprefixer = require('autoprefixer');
var precss = require('precss');
module.exports = {
devtool: 'cheap-module-eval-source-map',
entry: [
'webpack-hot-middleware/client',
'babel-polyfill',
'./src/index'
],
output: {
path: path.join(__dirname, 'dist'),
filename: 'bundle.js',
publicPath: '/assets/'
},
plugins: [
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.HotModuleReplacementPlugin(),
new webpack.NoEmitOnErrorsPlugin(),
new webpack.LoaderOptionsPlugin({
options: {
postcss: [
autoprefixer(),
]
}
})
],
module: {
rules : [
{
test: /\.js$/,
use: [
{
loader: 'react-hot-loader',
},
{
loader: 'babel-loader',
},
],
include: [
path.resolve(__dirname, "src"),
]
},
{
test: /\.js$/,
loader: 'eslint-loader',
enforce: 'pre',
include: [
path.resolve(__dirname, "src"),
]
},
{
test: /\.css$/,
use: [
"style-loader",
{
loader: "css-loader",
options: {
modules: true,
sourceMap: true,
importLoaders: 1,
// localIdentName: "[name]--[local]--[hash:base64:8]"
localIdentName: "[local]"
}
},
"postcss-loader" // has separate config, see postcss.config.js nearby
]
},
{
test: /\.(jpg|jpeg|gif|png)$/,
exclude: /node_modules/,
loader:'url-loader?limit=1024&name=images/[name].[ext]'
},
{
test: /\.(woff|woff2|eot|ttf|svg)$/,
exclude: /node_modules/,
loader: 'url-loader?limit=1024&name=fonts/[name].[ext]'
}
]
}
};
Answer the question
In order to leave comments, you need to log in
you take pictures from a folder assets
and then after assembly you send them there. somehow it's strange. maybe it's better to create a folder /src/images
, and in the config
{
test: /\.(jpg|jpeg|gif|png)$/,
include: path.resolve(__dirname, "src/images"),
loader:'url-loader?limit=1024&name=images/[name].[ext]'
}
body {
background: url(../../assets/back.jpg);
background-size: cover;
font-family: 'Open Sans', sans-serif;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question