noppa / ng-hot-reload

Hot reloading for AngularJS apps.
MIT License
43 stars 8 forks source link

🔥 ng-hot-reload

Developing legacy apps doesn't need to suck (so bad)!

ng-hot-reload uses a suite of clever tricks (read: dirty, unstable hacks) to "hot" reload AngularJS (version 1.x) components and directives, reducing the need to refresh page between code updates.
Moreover, it doesn't depend on build tools like Webpack or specific JavaScript features like ES6 modules. Webpack is superb and ESNext features are awesome, but many great projects predate those and I think they deserve to have the same great development experience that modern <name-your-favourite-JS-library> apps do.

hot

Hot Module Replacement (HMR) is a technique popularized by Webpack, React and Redux to modify the modules of an application while the app is running, without a full reload. This library provides the tools to do something very similar for angularjs apps: when a file is modified, ng-hot-reload swaps the implementation of the changed directive or component on a running browser environment so that you'll be able to see the result of code changes immediately.
It also attempts to preserve some of the component state so that your debugging efforts don't need to start from scratch, although admittedly this feature is not as thorough or reliable as the state reloading that you would get with Redux.

Usage

Warning: Some of the stuff that this library does is quite hackish and use angular's internal/private apis, so they might break in the future. Luckily this is a development tool that you can easily opt in and out of, so it doesn't really matter if it's "production ready" or not.

This repository is a monorepo that contains these four packages:

Limitations

ng-hot-reload is a tool focused on making UI development more pleasant with AngularJS. It's not perfect, and it won't cover 100% of the code edits you make — a full reload is still needed every once in a while. Understanding the limitations of this library may help you achieve the best development experience with hot reloading.

For a noncomprehensive guide to what you might want to do or avoid doing with the library, see Limitations.

Installation for Webpack build

npm install --save-dev ng-hot-reload-loader

Example webpack config is in the demo package, demo project sources are in webpack-example folder.

Installation for Gulp or any other build setup

npm install --save-dev ng-hot-reload-standalone

Check out gulpfile.js in the demo package, demo project sources are in gulp-example folder.

Client options

The options that you can pass to the library depend on the package you use, but these options should work in all:

License

MIT