1 | npm create-react-app |
The steps are essentially taken form a youtube tutorial:
Before going any further, our directory will look like:
We start off installing all necessary dependency:
1 2 3 4 | npm i react react-dom npm i --save-dev webpack-dev-server webpack-cli npm install @babel/cli @babel/core @babel/node @babel/preset-env @babel/preset-react html-webpack-plugin -D npm install npm install -D babel-loader |
1 2 3 4 5 6 7 8 9 10 11 12 | <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta http-equiv="X-UA-Compatible" content="ie=edge" /> <title>My React App</title> </head> <body> <div id="app"></div> </body> </html> |
<div>
element with id "app" is a destination to which we build our react component. Next we configure our webpack and babel as follows: Create webpack.config.js and write
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | const path = require( "path" ); const HtmlWebpackPlugin = require( "html-webpack-plugin" ); module.exports = { entry: "./src/index.js" , output: { path: path.join(__dirname, "/dist" ), filename: "index_bundle.js" }, module: { rules: [ { test: /\.js$/, exclude: /node_modules/, use: { loader: "babel-loader" , options: { presets: [ "@babel/preset-env" , "@babel/preset-react" ] } } } ] }, plugins: [ new HtmlWebpackPlugin({ template: "./src/index.html" }) ] }; |
1 2 3 | module.exports = { presets: [ "@babel/preset-env" , "@babel/preset-react" ] }; |
1 2 3 4 5 6 | import React from "react" ; import ReactDOM from "react-dom" ; import App from "./components/App" ; ReactDOM.render(<app>, document.getElementById( "app" )); </app> |
1 2 3 4 5 6 7 8 9 10 11 12 | import React, { Component } from "react" ; class App extends Component { render() { return ( <div> <h1>My React App</h1> </div> ); } } export default App; |
1 | "start": "webpack-dev-server --mode development --open --hot" |
My next target is to study how react and .net MVC interact to each other, i.e., using react in ASP.net framework.
No comments:
Post a Comment