I am new to UI technologies. I am trying my hands at reactjs along with webpack and babel I created an app using create-react-app plugin after installing it using npm. I cd into the src folder and do npm start, it launches the browser and shows the demo page. I am trying to add babel and webpack into this demo, but unfortunately it does not work. I open the index.html page in the brower and it does not show the jsx file content I am following https://www.codementor.io/tamizhvendan/beginner-guide-setup-reactjs-environment-npm-babel-6-webpack-du107r9zr
I am not sure why this does not work, can some please help with this ?
index.jsx
import React from 'react';
import {render} from 'react-dom';
class App extends React.Component {
render () {
return <p> Hello React!</p>;
}
}
render(<App/>, document.getElementById('app'));
index.html
<html>
<head>
<meta charset="utf-8">
<title>React.js using NPM, Babel6 and Webpack</title>
</head>
<body>
<div id="app" />
<script src="public/bundle.js" type="text/javascript"></script>
</body>
</html>
.babelrc file
{
"presets" : ["es2015", "react"]
}
webpack.config.js file
var webpack = require('webpack');
var path = require('path');
var BUILD_DIR = path.resolve(__dirname, 'src/client/public');
var APP_DIR = path.resolve(__dirname, 'src/client/app');
var config = {
entry: APP_DIR + '/index.jsx',
output: {
path: BUILD_DIR,
filename: 'bundle.js'
},
module : {
loaders : [
{
test : /\.jsx?/,
exclude : /(node_modules)/,
include : APP_DIR,
loader : 'babel-loader'
}
]
}
};
module.exports = config;
create-react-app
already includes webpack and Babel, it's one of its big selling points. It's mentioned in Get Started Immediately: You don’t need to install or configure tools like Webpack or Babel. They are preconfigured and hidden so that you can focus on the code. Have you read the User Guide or at least the README? - Michael Jungo