Code Monkey home page Code Monkey logo

react-boilerplate's Introduction

React Boilerplate

It is well known project in React needs scaffolding, compiler configurations, bundlers, and linter setup.

This project presents a simple setup to get your React + Typescript project up and running.

Popular Bootstraping Tools

create-react-app

Nextjs

Manual boostraping approach

Tech stack

  • Package manager: pnpm (npm and yarn are just fine)

Step-by-step

  1. Create a package.json Run this command in the root folder:
pnpm init

This will make you go through a CLI configuration setup.

  1. Create a .gitignore And add all files and folders that doesn't make sense to add to your remote repository, such as node_modules and build.

  2. Install React libraries and Typescript If you need a specific version, add @xx.xx as sufix.

pnpm install react react-dom typescript --save

Don't forget to install the types library.

pnpm install @types/react-dom --save-dev

You still need to add a tsconfig.json. You can reference the one that is located in this repo.

  1. Install transpilers (Babel)
pnpm install @babel/core @babel/preset-env @babel/preset-react @babel/preset-typescript --save-dev

Add also a configuration file or Babel, .babelrc:

{
  "presets": [
    "@babel/preset-env",
    "@babel/preset-react",
    "@babel/preset-typescript"
  ]
}
  1. Install bundler (Webpack)
pnpm install webpack webpack-cli webpack-dev-server ts-loader babel-loader css-loader style-loader html-webpack-plugin --save-dev

You can also configure other bundlers, such as Parcel.

Now, you need to create and add configurations on the webpack.config.js file. You can check the one in this repo for referencing.

  1. Script time!

Now, you need to add scripts into your package.json to speed up your environment.

"scripts": {
  "start": "webpack-dev-server --mode=development --open --hot",
  "build": "webpack --mode=production"
}

Good to have

Linter and formatters

Linters help to flag and fix syntax issues. Formatters help maintain consistency throughout the codebase.

Eslint

First, install the linter (using Eslint in this case):

pnpm install eslint --save-dev

Then, start configuration with:

npx eslint --init

For it to work with Prettier, our chosen formatter, we need to install some extra Eslint configurations:

pnpm install eslint-config-prettier eslint-plugin-prettier prettier --save-dev

This is will make Eslint be responsible to make the formatting.

You can check the output file and additional configurations on the .eslintrc.json. Additionally, you can check .prettierrc for formatting configuration.

You still need to install Prettier extension on your editor for it to work, though.

react-boilerplate's People

Contributors

yogmel avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.