Giter VIP home page Giter VIP logo

react-boilerplate's Introduction

A boilerplate/reference I developed to help kickstart my React projects. Heavily inspired by Spectrum.

Features

  • Babel and webpack overrides via react-app-rewired and customize-cra, without having to eject.
  • React Router, Redux (with redux-thunk), and styled-components preconfigured and ready right out of the box.
  • Flexible, organized, and sane file structure inspired by Spectrum.
  • Support for build analyzation, just install source-map-explorer by doing yarn global add source-map-explorer, and then run yarn analyze.
  • Support for using absolute paths when importing ES6 modules.

I recommend using yarn as the package manager for this. Otherwise, delete the yarn.lock before running npm install.

Getting Started

  1. Clone the repository with git clone --depth 1 https://github.com/WilsonCWong/react-boilerplate.git.
  2. Move to the directory you cloned it to: cd <THE_PROJECT_DIRECTORY>.
  3. Run yarn install to install dependencies.
  4. Run the project with yarn start.
  5. Delete the .git folder to and run git init to reinitialize the git repository.

Note that some folders have a dummy .gitignore file, which is used to maintain folder structure in the Git repository. For now, you can remove these manually. I plan to write a setup script later on to automate this.

File Structure

public - This has all the static files that will be served to the client on the frontend. It includes html files, icons, images, fonts, etc.

shared - Shared JavaScript code.

src - The source code of the frontend SPA.

  • actions - Redux action creators. These should be grouped by category, e.g., actions (this includes thunks!) related to todos should be in todos.js.
  • components - Global components. These are reuseable components such as buttons, inputs, navbars, etc.
  • hooks - Custom hooks that can be used.
  • pages - The pages/routes of the app. Each folder here corresponds to a route and contains the component that renders that route. These folders can also have another components folder within that holds local components, which are components only used for rendering that page.
  • reducers - The redux reducers go here. Again, each reducer should correspond to its category, e.g., todos.js holds the reducer for todo actions. These reducers are combined together in index.js to create the root reducer.
  • store - This folder contains an index.js file, which has a method for creating and initializing the store by injecting all middleware, initial state, and the root reducer.
  • utils - Helper/Utility methods.
  • globalStyles.css - This is a stylesheet for global styles. You can switch this to SASS if you need to pretty easily. Just install the dependency. I'm also aware you can use styled-components for this using createGlobalStyle, but that has some possible issues. Refer to this issue.
  • index.js - The heart of the SPA. The component tree is started and mounted here, routes are defined, and the redux store is initialized here as well.

config-overrides.js - The configuration for customize-cra. Use this to add babel plugins or webpack overrides. Refer to their documentation.

react-boilerplate's People

Contributors

wilsoncwong 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.