All Projects β†’ PatrickJS β†’ Angular Hmr

PatrickJS / Angular Hmr

Licence: apache-2.0
πŸ”₯ Angular Hot Module Replacement for Hot Module Reloading

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Angular Hmr

Sass Vars Loader
Use Sass variables defined in Webpack config or in external Javascript or JSON files
Stars: ✭ 112 (-77.14%)
Mutual labels:  webpack, hmr, hot-reload, loader
Node Hot Loader
Hot module replacement (hot reload) for Node.js applications. Develop without server restarting.
Stars: ✭ 111 (-77.35%)
Mutual labels:  webpack, hmr, hot-reload, loader
ngx-smart-loader
Smart loader handler to manage loaders everywhere in Angular apps.
Stars: ✭ 28 (-94.29%)
Mutual labels:  angular2, loader, angular4
Aspnetcore Angular Universal
ASP.NET Core & Angular Universal advanced starter - PWA w/ server-side rendering for SEO, Bootstrap, i18n internationalization, TypeScript, unit testing, WebAPI REST setup, SignalR, Swagger docs, and more! By @TrilonIO
Stars: ✭ 1,455 (+196.94%)
Mutual labels:  hmr, angular2, angular4
Extracted Loader
It reloads extracted stylesheets extracted with ExtractTextPlugin
Stars: ✭ 67 (-86.33%)
Mutual labels:  webpack, hot-reload, loader
Template Rwb
A full-featured Webpack setup with hot-reload
Stars: ✭ 165 (-66.33%)
Mutual labels:  webpack, hmr, hot-reload
Nebular
πŸ’₯ Customizable Angular UI Library based on Eva Design System 🌚✨Dark Mode
Stars: ✭ 7,368 (+1403.67%)
Mutual labels:  webpack, angular2, angular4
Fuse Box
A blazing fast js bundler/loader with a comprehensive API πŸ”₯
Stars: ✭ 4,055 (+727.55%)
Mutual labels:  hmr, hot-reload, loader
React Hot Loader Loader
A Webpack Loader that automatically inserts react-hot-loader to your App πŸ‘¨β€πŸ”¬
Stars: ✭ 176 (-64.08%)
Mutual labels:  webpack, hmr, loader
Ng Http Loader
🍑 Smart angular HTTP interceptor - Intercepts automagically HTTP requests and shows a spinkit spinner / loader / progress bar
Stars: ✭ 327 (-33.27%)
Mutual labels:  loader, angular2, angular4
Markdown Loader
markdown loader for webpack
Stars: ✭ 335 (-31.63%)
Mutual labels:  webpack, loader
React Webpack Boilerplate
Minimalistic ES6+ React boilerplate with Hot Reloading using Webpack 4 and Babel 7
Stars: ✭ 336 (-31.43%)
Mutual labels:  webpack, hot-reload
Angular2 Toaster
Angular2-toaster is an asynchronous, non-blocking Angular Toaster Notification library
Stars: ✭ 333 (-32.04%)
Mutual labels:  angular2, angular4
Ionic Audio
An audio player for Ionic 3 and Angular 4. Works with HTML 5 audio or native audio using Cordova Media plugin.
Stars: ✭ 332 (-32.24%)
Mutual labels:  angular2, angular4
Ngx Monaco Editor
Monaco Editor component for Angular 2 and Above
Stars: ✭ 347 (-29.18%)
Mutual labels:  angular2, angular4
Vueniverse
Full stack, user based, PWA, Vue template.
Stars: ✭ 339 (-30.82%)
Mutual labels:  webpack, hot-reload
Angular Material Dashboard
A material-design dashboard by using angular
Stars: ✭ 347 (-29.18%)
Mutual labels:  angular2, angular4
Sass Loader
Compiles Sass to CSS
Stars: ✭ 3,718 (+658.78%)
Mutual labels:  webpack, loader
Rebirth
GreenGerong(η ΄η‹Ό) blog with Angular4.
Stars: ✭ 380 (-22.45%)
Mutual labels:  angular2, angular4
Ngx Meta
Dynamic page title & meta tags utility for Angular (w/server-side rendering)
Stars: ✭ 331 (-32.45%)
Mutual labels:  angular2, angular4

Angular HMR

Angular Hot Module Replacement

Angular-HMR Hot Module Reloading for Webpack and Angular. All versions of Angular and Webpack will work with this module

npm install @angularclass/hmr

hmr-state-dom

main.browser.ts

import { removeNgStyles, createNewHosts, bootloader } from '@angularclass/hmr';

@NgModule({
  bootstrap: [ App ],
  declarations: [ App ],
  imports: [
    // Angular 2
    BrowserModule,
    FormsModule,
    HttpModule,
    RouterModule.forRoot([], {
      useHash: true
    }),
    // app
    appModule
    // vendors
  ],
  providers: []
})
class MainModule {
  constructor(public appRef: ApplicationRef) {}
  hmrOnInit(store) {
    if (!store || !store.state) return;
    console.log('HMR store', store);
    console.log('store.state.data:', store.state.data)
    // inject AppStore here and update it
    // this.AppStore.update(store.state)
    if ('restoreInputValues' in store) {
      store.restoreInputValues();
    }
    // change detection
    this.appRef.tick();
    delete store.state;
    delete store.restoreInputValues;
  }
  hmrOnDestroy(store) {
    var cmpLocation = this.appRef.components.map(cmp => cmp.location.nativeElement);
    // recreate elements
    store.disposeOldHosts = createNewHosts(cmpLocation)
    // inject your AppStore and grab state then set it on store
    // var appState = this.AppStore.get()
    store.state = {data: 'yolo'};
    // store.state = Object.assign({}, appState)
    // save input values
    store.restoreInputValues  = createInputTransfer();
    // remove styles
    removeNgStyles();
  }
  hmrAfterDestroy(store) {
    // display new elements
    store.disposeOldHosts()
    delete store.disposeOldHosts;
    // anything you need done the component is removed
  }
}

export function main() {
  return platformBrowserDynamic().bootstrapModule(MainModule)
    // use `hmrModule` or the "@angularclass/hmr-loader"
    .then((ngModuleRef: any) => {
      // `module` global ref for webpackhmr
      // Don't run this in Prod
      return hmrModule(ngModuleRef, module);
    });
}

// boot on document ready
bootloader(main);

bootloader is only needed to detect that the dom is ready before bootstraping otherwise bootstrap. This is needed because that dom is already ready during reloading.

Important Helpers

  • removeNgStyles: remove angular styles
  • createNewHosts and disposeOldHosts: recreate root elements for bootstrapping
  • bootloader: boot on document ready or boot if it's already ready
  • createInputTransfer and restoreInputValues: transfer input DOM state during replacement

Production

In production you only need bootloader which just does this:

export function bootloader(main) {
  if (document.readyState === 'complete') {
    main()
  } else {
    document.addEventListener('DOMContentLoaded', main);
  }
}

You would bootstrap your app the normal way, in production, after dom is ready. Also, in production, you should remove the loader:


@NGRX/platform (NGRX 4.x.x)

To hook into NGRX 4 you simply need to supply a reducer to set the state, and include it in your development metaReducers.

// make sure you export for AoT
export function stateSetter(reducer: ActionReducer<any>): ActionReducer<any> {
  return function(state: any, action: any) {
    if (action.type === 'SET_ROOT_STATE') {
      return action.payload;
    }
    return reducer(state, action);
  };
}

In your root reducer you can do something like this to include it in your metaReducers. You should access your environment here and only include this in development.

/**
 * By default, @ngrx/store uses combineReducers with the reducer map to compose
 * the root meta-reducer. To add more meta-reducers, provide an array of meta-reducers
 * that will be composed to form the root meta-reducer.
 */
export const metaReducers: ActionReducer<any, any>[] = [stateSetter]

Simply supply the metaReducer to the StoreModule and your hmr is hooked in.

 StoreModule.forRoot(reducers, { metaReducers }),

enjoy β€” PatrickJS

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