Skip to content

A react boilerplate project featuring webpack 4, HMR, code splitting, mobx, SSR

Notifications You must be signed in to change notification settings

mobxjs/react-mobx-boilerplate

 
 

Repository files navigation

React MobX Boilerplate

A modern web development boilerplate for React + MobX + Webpack 4.

Stack

  • React
  • MobX
  • Webpack 4
  • Typescript
  • PostCSS + CSS Modules

Features

  • HMR of components and store
  • Code-splitting out of the box
  • Simple routing (without react-router)
  • Server-side rendering with async data loading

Installation and Starting

Development server

npm start
> visit localhost:3000

Building for production

npm run build
> serve index.html

Building for node (server-side rendering)

npm run build-node
> require('build/app.node.js').default('/users')

Structure

During app development, you should care about these files:

react-mobx-boilerplate/
└───src/
    │
    └───components/
    |     Core.tsx
    |     ...
    |
    └───stores/
    |     AppState.ts
    |
    └───routes.tsx

The rest can be extended if needed:

  1. index.html
  2. index.ts - Entry point for browser bundle
  3. index.node.ts - Entry point for node (server-side rendering) bundle
  4. App.ts - Manages routing, contains a reference to AppState
  5. root.tsx - Container component for the app
  6. webpack/webpack-dev-server.js - Script to run the development server
  7. webpack/webpack.config.js - Webpack configuration for browser bundle
  8. webpack/webpack.config.node.js - Webpack configuration for node (server-side rendering) bundle

Typically, when adding a new page you'd add a route for it in routes.tsx containing the component to render. Note that the component isn't imported directly but with import() for code splitting. Then you can add the component to the components folder and the relevant state to the store.

This project is a boilerplate and does not impose strong architectural decisions on users.

TODO

  • Full SSR workflow
  • Optimize bundles
  • Static assets (images etc.)
  • Make work with remote chrome debugging
  • Add linter
  • Add PostCSS plugins
  • Use webpack-dev-middleware instead of webpack-dev-server

About

A react boilerplate project featuring webpack 4, HMR, code splitting, mobx, SSR

Resources

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

Packages

No packages published

Languages

  • TypeScript 64.4%
  • JavaScript 33.6%
  • HTML 1.3%
  • CSS 0.7%