I am new to webpack. I am learning react and building environment for it using webpack.
I have webpack-config.js
var path = require('path');
module.exports = {
mode: 'production',
entry: './script.js',
output:
{
path: path.resolve(__dirname, 'src'),
filename: 'transpiled.js'
},
module:
{
loaders: [
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/,
query:
{
presets: ['es2015','react']
}
}
]
}
}
and script.js
import React from 'react';
import ReactDOM from 'react-dom';
ReactDOM.render(
<h1>Hello world</h1>
document.getElementByIdName('first')
);
and index.html
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<div class="first"></div>
<script src="transpiled.js"></script>
</body>
</html>
in Pakage.json file I have written
"scripts": {
"it": "webpack-dev-server --hot"
},
But when i run the npm with "npm run it", it shows me the error of
WARNING in configuration The 'mode' option has not been set. Set 'mode' option to 'development' or 'production' to enable defaults for this environment. ERROR in multi -dev-derver/client?http://localhost:8080 webpack/hot/dev-server ./src Module not found: Error : Cant resolve './src' in D:\React Js \LearnReact' @multi -dev-derver/client?http://localhost:8080 webpack/hot/dev-server ./src i ?wdm?: failed to Compile.
Please help me i am really stuck and want to know the solution.
srcfolder? - brkwebpack.config.js. Take a look at the docs webpack.js.org/configuration - konekoya