A simple cli to bootstrap build and development server for JavaScript with React bundle.
yarn add basic-react-scripts
In the project's root folder, create the source files with the structure:
/src
index.html
index.jsx
If using typescript:
/src
index.html
index.tsx
index.html
:
Just a regular html file with a div with id = "app"
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Title_of_your_project_here</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
</head>
<body>
<div id="app"></div>
</body>
</html>
index.js
or index.tsx
:
Inserting the React code into a div with id = "app".
import React from 'react'
import ReactDOM from 'react-dom'
ReactDOM.render(<h1>Hello, World</h1>, document.getElementById('app'));
To use this library to build and start a developer server, add this scripts on the package.json file:
"scripts": {
"start": "basic-react-scripts start",
"build": "basic-react-scripts build",
},
To support typescript:
"scripts": {
"start": "basic-react-scripts start --ts",
"build": "basic-react-scripts build --ts",
},
flag | command description |
---|---|
--ts | enable typescript parser |