Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

angular2-async-route-loader

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

angular2-async-route-loader

angular2 async route loader

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

Angular2 load-children loader

This is a webpack loader to Angular2 lazy module loading.

It's recommended to use this loader with webpack 2.x.

  • INPUT:
export const appRoutes: Routes = [
  {path: "", component: MainHomeComponent},
  {path: "about", component: MainAboutComponent },
  {path: "sub", loadChildren: "./sub.module#SubModule" },
];
  • OUTPUT:
export const appRoutes: Routes = [
  {path: "", component: MainHomeComponent},
  {path: "about", component: MainAboutComponent },
  {path: "sub", loadChildren: () => require("./sub.module")("SubModule") },
];

And this loader return a function to call the require function with .ngfactory suffix if the resource is generated by compiler-cli:

export const appRoutes: Routes = [
  {path: "", component: MainHomeComponent},
  {path: "about", component: MainAboutComponent },
  {path: "sub", loadChildren: () => require("./sub.module.ngfactory")("SubModuleNgFactory") },
];

Install

npm install angular2-load-children-loader -D
npm install @types/node -D

or

typings install node

Using with es6-promise-loader

export const appRoutes: Routes = [
  {path: "", component: MainHomeComponent},
  {path: "about", component: MainAboutComponent },
  {path: "sub", loadChildren: "es6-promise!./sub.module#SubModule"}
];

Working demonstration

The following repository uses this loader:

Quramy/ng2-lazy-load-demo

Why?

To load sub modules asynchronously with webpack, you use only es6-promise-loader. For example:

import { Routes, RouterModule } from "@angular/router";
import { MainHomeComponent } from "./main-home.component";
import { MainAboutComponent } from "./main-about.component";

export function loadSubModule(): any {
  return require("es6-promise!../sub/sub.module")("SubModule");
}

export const appRoutes: Routes = [
  {path: "", component: MainHomeComponent},
  {path: "about", component: MainAboutComponent },
  {path: "sub", loadChildren: loadSubModule},
];

OK, it works pretty well. But wait. It doesn't work in Angular2 AoT(offline compile) mode.

In AoT context the loadSubModule function should return not SubModule but SubModuleNgFactory(generated by the ngc command). In other words, to keep routing configurations to work in the both JiT and AoT context, you should switch the sub module to load as this loader does.

License

MIT

Keywords

FAQs

Package last updated on 26 Sep 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc