All Projects → raquo → minimal-hapi-react-webpack

raquo / minimal-hapi-react-webpack

Licence: MIT license
Minimal Hapi + React + Webpack + HMR (hot module reloading) Sandbox

Programming Languages

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

Projects that are alternatives of or similar to minimal-hapi-react-webpack

express-mysql-rest
Building the simple api with sequelize, mysql and express js. this repository contains the code about how to use sequelize with mysql at express js. for example i have provide the crud operation to this repository. You can also testing the api with chai and mocha with chai-http by this repository
Stars: ✭ 25 (-54.55%)
Mutual labels:  mocha, nodemon, chai
Earl
☕ Ergonomic, modern and type-safe assertion library for TypeScript
Stars: ✭ 153 (+178.18%)
Mutual labels:  mocha, chai
Cracking The Coding Interview Javascript Solutions Ctci
Javascript solutions to Cracking the Coding Interview (CTCI)
Stars: ✭ 139 (+152.73%)
Mutual labels:  mocha, chai
Redux Actions Assertions
Simplify testing of redux action and async action creators
Stars: ✭ 177 (+221.82%)
Mutual labels:  mocha, chai
Typescript Restful Starter
Node.js + ExpressJS + Joi + Typeorm + Typescript + JWT + ES2015 + Clustering + Tslint + Mocha + Chai
Stars: ✭ 97 (+76.36%)
Mutual labels:  mocha, chai
Hapi Starter Kit
Hapi.js based REST boilerplate which uses latest ES7/ES8 features (async/await) with code coverage and follows best pratices
Stars: ✭ 103 (+87.27%)
Mutual labels:  mocha, hapi
TvrboReact
Dream starter project: React, Redux, React Router, Webpack
Stars: ✭ 13 (-76.36%)
Mutual labels:  mocha, chai
Bombanauts
Bombanauts, inspired by the original Bomberman game, is a 3D multiplayer online battle arena (MOBA) game where players can throw bombs at each other, make boxes explode, and even other players!
Stars: ✭ 54 (-1.82%)
Mutual labels:  mocha, chai
chai-exclude
Exclude keys to compare from a deep equal operation with chai expect or assert.
Stars: ✭ 33 (-40%)
Mutual labels:  mocha, chai
fetch-action-creator
Fetches using standardized, four-part asynchronous actions for redux-thunk.
Stars: ✭ 28 (-49.09%)
Mutual labels:  mocha, chai
js-stack-from-scratch
🌺 Russian translation of "JavaScript Stack from Scratch" from the React-Theming developers https://github.com/sm-react/react-theming
Stars: ✭ 394 (+616.36%)
Mutual labels:  mocha, chai
Karma Webpack Example
Karma + Webpack + Mocha + Chai + Istanbul
Stars: ✭ 88 (+60%)
Mutual labels:  mocha, chai
Cookiecutter Webpack
Boilerplate for webpack 2, babel, react + redux + hmr, and karma. Can be inserted into existing django projects.
Stars: ✭ 87 (+58.18%)
Mutual labels:  mocha, hmr
Javascript Testing Best Practices
📗🌐 🚢 Comprehensive and exhaustive JavaScript & Node.js testing best practices (August 2021)
Stars: ✭ 13,976 (+25310.91%)
Mutual labels:  mocha, chai
React Base
atSistemas React/Redux Isomorphic Platform
Stars: ✭ 82 (+49.09%)
Mutual labels:  mocha, chai
React Redux Universal Boilerplate
An Universal ReactJS/Redux Boilerplate
Stars: ✭ 165 (+200%)
Mutual labels:  mocha, hot-reload
vue-hot-reload-loader
Enable hot module replacement (HMR) on your Vue components
Stars: ✭ 20 (-63.64%)
Mutual labels:  hot-reload, hot-module-replacement
Jobsort
job board that queries hacker news who is hiring job listings from a database and sorts by tech the user knows and how well the user knows them
Stars: ✭ 20 (-63.64%)
Mutual labels:  mocha, chai
Chakram
REST API test framework. BDD and exploits promises
Stars: ✭ 912 (+1558.18%)
Mutual labels:  mocha, chai
webpack-hmr
🔨Easy implementation of webpack Hot-Module-Replacement(hmr)
Stars: ✭ 120 (+118.18%)
Mutual labels:  hmr, hot-module-replacement

Minimal Hapi + React + Webpack + HMR Sandbox

This starter kit connects a hapi.js server with webpack dev server with react hot module reloading all set up.

Very basic production config is also in place.

You can use this starter kit to efficiently develop react components and applications that might talk to a Hapi.js backend.

The primary purpose of this repo however is to demonstrate how to wire together these technologies. The config files are organized to have an obvious single source of truth. I've added plenty of comments to explain which config does what.

Features

  • React (client) hot module reloading is configured with react-transform-hmr
  • ESLint error & warnings are logged to browser console
  • Application server (Hapi.js) is separate from webpack dev server (Express.js)
  • Hapi.js proxies requests for webpack assets to webpack dev server
  • Hapi.js is configured to serve static files, and a couple example routes
  • A separate sandbox entry point is set up for white room component development
  • Sample client-side React view with a counter to easily test hot module reloading (any time the page does a full reload, the counter resets).
  • Server-side React views instead of index.html (see /server-views). Isomorphism is easy to configure if needed using the same dependency.
  • Automatic application server reloading using nodemon
  • Babel transpilation of ES6 and JSX into browser-compatible ES5, both for server and client code. Use all the fancy stuff today!
  • Webpack assets are generated with content hashes in filenames for easy cache busting
  • Webpack assets are optimized with Uglify.js on production, removing dead code (TODO: add server-only code)
  • Webpack asset URLs are recorded in a file, and a helper method is provided to extract them for usage in HTML / JSX.
  • Basic testing setup with Mocha, Chai and jsdom

Configuration

  • Raw configuration parameters are stored in src/config/variables.js – this is the source of truth compiled for easy understanding of what goes where.
  • Webpack configuration is compiled using the parameters above in src/config/webpack-config.js
  • A couple tooling config files (e.g. .eslintignore) are generated from the config parameters as well, again, to make it clear what exactly is affected by the configs.

Usage

Dependencies

  • You need node.js v4+ installed globally on your machine. If using OS X, best to install node using Homebrew. Node v0.12 might work too, but I don't test it anymore.
  • npm dependencies are required to build and run the app in production.
  • npm devDependencies are additionally required to build and run the app in development.
  • Core dependencies: Hapi, Webpack, Babel 6, React, react-transform-hmr.

Development

  • git clone this repo to your local machine
  • cd into project folder
  • npm install to install dependencies
  • npm run dev to start Hapi application server
  • npm run webpack in another terminal session to start webpack dev server with hot module reloading
  • Visit http://localhost:3000 and open your browser's web development console
  • Try changing and saving src/components/counter.css – you'll see the changes applied to the page without the page itself reloading. How cool is that, eh?
  • ESLint errors are printed into webpack dev server output and also into the browser's console. To run ESLint separately from that, do npm run lint.

Production

  • git clone and npm install
  • npm run build to generate config files and webpack assets. This means we don't need to run webpack dev server in production.
  • npm start to start up node
  • Visit http://localhost:2000 (note the port is different from dev)
  • Build something people want, acquire paying customers, retire to New Zealand.

Caveats

  • Hot module reloading only works for react components and CSS files.
  • If you change files that cause nodemon to reload, HMR will temporarily break and you'll need to reload the page manually (or make another change to another file that is covered by HMR but does not trigger a server reload).
  • If you edit webpack-config.js or change the contents of node_modules (e.g. by installing a new dependency), you'll need to restart webpack dev server.
  • (TODO) Reloading while webpack is compiling loads a broken page. Ideally it should wait for webpack to finish compiling, and only then load the page.
  • (TODO) I didn't test webpack dev server https support. Might need a couple tweaks.

Resources

SurviveJS is a good introduction to React and Webpack.

Follow Dan Abramov and check out his projects, he knows a thing or two about react and hot module reloading.

This project uses ES6 language features. If you're not into that yet, check out Understanding ES6.

If something's not working in my setup, please file an issue on Github.

License

MIT. Go nuts.

Author

Nikita Gazarov + Contributors

[email protected]

@raquo

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