Skip to content

A minimal React app starter template built from scratch using Webpack and Babel. Includes a basic configuration for rapid development and production-ready builds. Perfect for understanding React setup without Create React App.

License

Notifications You must be signed in to change notification settings

rvsarish/react-starter-kit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

React App Starter

This project demonstrates how to set up a React application from scratch using Webpack and Babel. It provides a basic boilerplate for developing and running React applications.

Table of Contents


Installation

  1. Clone the repository or create a new directory:

    mkdir my-react-app
    cd my-react-app
  2. Initialize a new Node.js project:

    npm init -y
  3. Install required dependencies:

    npm install react react-dom
  4. Install development tools:

    npm install --save-dev webpack webpack-cli babel-loader @babel/core @babel/preset-env @babel/preset-react html-webpack-plugin

Project Structure

After completing the setup, your project directory should look like this:

my-react-app/
├── public/
│   └── index.html
├── src/
│   └── index.js
├── .babelrc
├── webpack.config.js
├── package.json
└── node_modules/

Key Files

  • public/index.html: Template HTML file with a root div.
  • src/index.js: Entry point for the React app.
  • .babelrc: Configuration for Babel to transpile modern JavaScript and React JSX.
  • webpack.config.js: Configuration for Webpack to bundle files and serve the app.

Scripts

Add the following scripts to your package.json file:

"scripts": {
    "start": "webpack serve --mode development",
    "build": "webpack --mode production"
}

Commands

  • Start Development Server: npm start
  • Build for Production: npm run build

Development Server

  1. Run the development server:
    npm start
  2. Open your browser and navigate to:
    http://localhost:3000
    

Building for Production

To create a production build:

npm run build

The output will be generated in the dist/ folder.


Key Configurations

Webpack

The webpack.config.js file contains the configuration for bundling and serving the app:

const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");

module.exports = {
  entry: "./src/index.js",
  output: {
    path: path.resolve(__dirname, "dist"),
    filename: "bundle.js",
  },
  module: {
    rules: [
      {
        test: /\.(js|jsx)$/,
        exclude: /node_modules/,
        use: "babel-loader",
      },
    ],
  },
  resolve: {
    extensions: [".js", ".jsx"],
  },
  plugins: [
    new HtmlWebpackPlugin({
      template: "./public/index.html",
    }),
  ],
  devServer: {
    static: path.resolve(__dirname, "dist"),
    port: 3000,
    open: true,
  },
};

Babel

The .babelrc file configures Babel to transpile modern JavaScript and JSX:

{
  "presets": ["@babel/preset-env", "@babel/preset-react"]
}

Example React App

The src/index.js file contains a basic React component:

import React from "react";
import ReactDOM from "react-dom";

const App = () => <h1>Hello, React!</h1>;

ReactDOM.render(<App />, document.getElementById("root"));

Future Improvements

  • Add CSS or SCSS support.
  • Include testing libraries like Jest or React Testing Library.
  • Implement routing using React Router.
  • Integrate state management using Redux or Context API.

License

This project is licensed under the MIT License.

About

A minimal React app starter template built from scratch using Webpack and Babel. Includes a basic configuration for rapid development and production-ready builds. Perfect for understanding React setup without Create React App.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published