All Projects → icflorescu → quickstart-express-react

icflorescu / quickstart-express-react

Licence: other
Combined live/hot-reloading quickstart for Express.js/React

Programming Languages

javascript
184084 projects - #8 most used programming language
CSS
56736 projects

Projects that are alternatives of or similar to quickstart-express-react

Analytics React
[DEPRECATED AND UNSUPPORTED] The hassle-free way to integrate analytics into your React application.
Stars: ✭ 146 (+812.5%)
Mutual labels:  quickstart
auth0-golang-web-app
Auth0 Integration Samples for Go Web Applications
Stars: ✭ 112 (+600%)
Mutual labels:  quickstart
electron-vite-quick-start
⚡ Full stack uses Vite to run Electron application, including main process.
Stars: ✭ 45 (+181.25%)
Mutual labels:  quickstart
Quick Start
💨 Empezá por acá!
Stars: ✭ 170 (+962.5%)
Mutual labels:  quickstart
Auth0 Angular Samples
Auth0 Integration Samples for Angular 2+ Applications
Stars: ✭ 227 (+1318.75%)
Mutual labels:  quickstart
auth0-laravel-api-samples
Auth0 Integration Samples for Laravel REST API Services
Stars: ✭ 18 (+12.5%)
Mutual labels:  quickstart
Auth0 Javascript Samples
Auth0 Integration Samples for Vanilla JavaScript Applications
Stars: ✭ 130 (+712.5%)
Mutual labels:  quickstart
analytics-angular
The hassle-free way to integrate analytics into your Angular application.
Stars: ✭ 69 (+331.25%)
Mutual labels:  quickstart
Cp All In One
docker-compose.yml files for cp-all-in-one , cp-all-in-one-community, cp-all-in-one-cloud
Stars: ✭ 239 (+1393.75%)
Mutual labels:  quickstart
seeder
Set up Seed app and start dev server by running one command
Stars: ✭ 44 (+175%)
Mutual labels:  quickstart
Mevn Stack
A Quickstart for building an Express API with a VueJS Admin Portal
Stars: ✭ 178 (+1012.5%)
Mutual labels:  quickstart
Auth0 Vue Samples
Auth0 Integration Samples for Vue.js Applications
Stars: ✭ 215 (+1243.75%)
Mutual labels:  quickstart
travis-ci-tutorial-java
Just to learn how to use travis-ci in a java project!
Stars: ✭ 38 (+137.5%)
Mutual labels:  quickstart
Spring Boot Angular4 Boilerplate
Quickstart for spring boot + angular 4 projects
Stars: ✭ 151 (+843.75%)
Mutual labels:  quickstart
nodejs-quickstart
This repository contains code samples for the Node.js Quick Start blog post series
Stars: ✭ 214 (+1237.5%)
Mutual labels:  quickstart
Create Html5 Boilerplate
npx quick start for html5-boilerplate
Stars: ✭ 136 (+750%)
Mutual labels:  quickstart
nanobox-engine-php
Engine for running PHP apps on Nanobox
Stars: ✭ 20 (+25%)
Mutual labels:  quickstart
auth0-android-sample
Auth0 Integration Samples for Android Applications
Stars: ✭ 61 (+281.25%)
Mutual labels:  quickstart
kotlin-quick-start
Template Kotlin application using Gradle
Stars: ✭ 29 (+81.25%)
Mutual labels:  quickstart
auth0-aspnet-owin-webapi-samples
Auth0 Integration Samples for ASP.NET OWIN Web API Services
Stars: ✭ 25 (+56.25%)
Mutual labels:  quickstart

A "real-life" Express + React application quickstart

Express, React, BrowserSync, Webpack, Nodemon

Combined live/hot-reloading for Express.js and React.

Motivation

TL;DR

While a simple, webpack-only based development scenario is perfectly suited for building SPAs, building multipage applications or websites require a different, more elaborated approach.

Background

While most React tutorials and quickstarts are focused exclusively on building SPAs (single-page applications), in real life your React application will often be running as part of a "classic" multipage application / website.

There's been lots of talk recently about server-side rendered React components or even about building your entire website as a client-side application. But rendering React components on the server is still unacceptably slow (as of December 2016), especially for websites that need to handle lots of traffic.

Also, we still need our server-generated content to be available and parsable by search engines. Admittedly, Google became smarter in regards to interpreting and client-side generated content, but it's not safe to completely rely on it, and other search engines are not so powerful yet.

That's why we still need to generate content on the server using tried & tested, fast, specialized template engines such as Pug, EJS, Vash, Dust, etc.

Also, the webpack-based hot-reloading solution provided by most tutorials and available quickstarts completely ignore the API your application is connecting to. But in real-life not all projects are developed by multiple teams; sometimes there's a single full-stack developer or team writing the entire codebase for an app or website, including the webpage templates, client-side JS code and server-side APIs.

Trying to use webpack hot-reloading for template-generated pages and API endpoints is possible to a certain degree, but it feels like trying to fit a square peg in a round hole: it requires you to structure your code in a certain way and make use of unsafe artifacts such as require cache busting, and it often results in FOUC when applying CSS changes.

Hence the need of a functional, truly general-purpose hot-reloading approach integrating the best of all worlds.

Features

  • Restart / full-page reload on server-side code change using nodemon and browsersync;
  • Full-page reload on template change using browsersync's watch mechanism;
  • Smart HMR on client-side code change using webpack@2.1.x;
  • Seamless CSS reloading with browsersync.

Starting

  • In development mode: npm run dev, then edit code and enjoy the auto-reload magic on localhost:3000;
  • In production mode: npm run build, then npm start.

Notes & Customizations

  • For demo purposes, server-side views are generated with Vash template engine, but you can use Pug, EJS, or anything else, as long as you make the necessary amendments in dev.js to instruct the browser to reload when one of your views changes.
  • A very simple/non-scalable JSON persistence mechanism based on lowdb and underscore-db is used as a server-side "database", for demo purposes. Make sure to npm uninstall -S lowdb underscore-db and replace with an appropriate data persistence layer.
  • A very simple gulp scenario is used for the sole purpose of transforming SCSS with node-sass and applying autoprefixer transformations with sourcemaps support in a single step. You can adapt it according to your own needs, or even fully replace it with a simple npm script if you're using Stylus with autoprefixer-stylus plugin or write your styles in plain CSS.
  • package.json contains simple npm scripts for running in development and production mode.
  • The quickstart provides a simple, yet efficient asset versioning mechanism based on package.json version: the static assets are served from a "virtual" root /static/x.x.x.x, where x.x.x.x is the package version. Just make sure to do an npm version bump as part of your deployment scenario (not provided here).
  • Efficient ES6 on the server with babel-preset-latest-minimal – configured in index.js.
  • In development mode, webpack-dev-middleware and webpack-hot-middleware are running as browsersync middlewares. This way we end up keeping the main Express application uncluttered by development-related code.
  • Webpack babel-loader is using stage-2 and react presets and react-hot-loader@3 – configured in webpack.config.js.
  • On the server, the global.Promise is replaced with bluebird for performance reasons – this is configured in index.js. Simply remove it if you don't like the idea.

Contributing

PRs are welcomed, but keep in mind this is just one of the many quickstart alternatives available in the wild, and it's not intended to cover all possible use-cases (or yours in particular).

Before raising issues or asking for help

I'm getting lots of questions from people just learning to do web development or simply looking to solve a very specific problem they're dealing with. While I will answer some of them for the benefit of the community, please understand that open-source is a shared effort and it's definitely not about piggybacking on other people's work. On places like GitHub, that means raising issues is encouraged, but coming up with useful PRs is a lot better. If I'm willing to share some of my code for free, I'm doing it for a number of reasons: my own intellectual challenges, pride, arrogance, stubbornness to believe I'm bringing a contribution to common progress and freedom, etc. Your particular well-being is probably not one of those reasons. I'm not in the business of providing free consultancy, so if you need my help to solve your specific problem, there's a fee for that. If you understand that and wish to employ my services, don't hesitate to drop me a line on my GitHub email account.

Credits

If you find this repo useful, don't hesitate to give it a star, spread the word or even endorse the author on LinkedIn.

License

ISC-licensed by Ionut-Cristian Florescu. Feel free to use and abuse.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].