i have created an "hello-world" react app using create-react-app command, then i tried to run the same files using webpack, but it does not working properly, like .ico, .css files are not rendering to the screen.. please help me to solve this issue.
webpack.config.js
const path = require('path');
module.exports = {
entry: './src/index.js',
output: {
path: path.join(__dirname, 'public'),
filename: 'bundle.js'
},
module: {
rules: [{
loader: 'babel-loader',
test: /\.js$/,
exclude: /node_modules/
},
{
test: /\.css$/,
exclude: /node_modules/,
use: [
{
loader: 'style-loader'
},
{
loader: 'css-loader',
options: {
modules: true,
// camelCase: true,
sourceMap: true
}
}
]
},
{
test: /\.svg$/,
loaders: [
'babel-loader',
{
loader: 'react-svg-loader',
query: {
jsx: true
}
},
]
},
{
test: /\.json$/,
loader: 'json-loader',
},
{
test: /\.(jpg|jpeg|gif|png|ico)$/,
exclude: /node_modules/,
loader:'file-loader?name=img/[path][name].[ext]&context=./app/images'
}
]
},
devtool: 'cheap-module-eval-source-map',
devServer: {
contentBase: path.join(__dirname, 'public')
}
};
package.json
{
"name": "indecision-app",
"version": "1.0.0",
"main": "index.js",
"author": "Andrew Mead",
"license": "MIT",
"scripts": {
"serve": "live-server public/",
"build": "webpack",
"start": "webpack-dev-server"
},
"dependencies": {
"json-loader": "^0.5.7",
"live-server": "^1.2.0",
"react": "15.6.1",
"react-dom": "15.6.1",
"react-svg-loader": "^2.1.0",
"style-loader": "^0.20.3",
"validator": "8.0.0"
},
"devDependencies": {
"babel-cli": "6.24.1",
"babel-core": "6.25.0",
"babel-loader": "7.1.1",
"babel-preset-env": "1.5.2",
"babel-preset-react": "6.24.1",
"css-loader": "^0.28.11",
"file-loader": "^1.1.11",
"html-webpack-plugin": "^3.2.0",
"webpack": "^2.7.0",
"webpack-cli": "^2.0.14",
"webpack-dev-server": "2.5.1"
}
}
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="theme-color" content="#000000">
<link rel="manifest" href="%PUBLIC_URL%/manifest.json">
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
<title>React App</title>
</head>
<body>
<noscript>
You need to enable JavaScript to run this app.
</noscript>
<div id="root"></div>
<script src="/bundle.js"></script>
</body>
</html>
.babelrc
{
"presets": ["env", "react"]
}
Remaining file are same as auto-generated while creating create-react-app. help me to solve this issue