
Security News
NVD Quietly Sweeps 100K+ CVEs Into a “Deferred” Black Hole
NVD now marks all pre-2018 CVEs as "Deferred," signaling it will no longer enrich older vulnerabilities, further eroding trust in its data.
angular2-load-children-loader
Advanced tools
This is a webpack loader to Angular2 lazy module loading.
It's recommended to use this loader with webpack 2.x.
export const appRoutes: Routes = [
{path: "", component: MainHomeComponent},
{path: "about", component: MainAboutComponent },
{path: "sub", loadChildren: "./sub.module#SubModule" },
];
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") },
];
npm install angular2-load-children-loader -D
npm install @types/node -D
or
typings install node
export const appRoutes: Routes = [
{path: "", component: MainHomeComponent},
{path: "about", component: MainAboutComponent },
{path: "sub", loadChildren: "es6-promise!./sub.module#SubModule"}
];
The following repository uses this loader:
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.
MIT
FAQs
A webpack loader for ng2 lazy loading
We found that angular2-load-children-loader demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
NVD now marks all pre-2018 CVEs as "Deferred," signaling it will no longer enrich older vulnerabilities, further eroding trust in its data.
Research
Security News
Lazarus-linked threat actors expand their npm malware campaign with new RAT loaders, hex obfuscation, and over 5,600 downloads across 11 packages.
Security News
Safari 18.4 adds support for Iterator Helpers and two other TC39 JavaScript features, bringing full cross-browser coverage to key parts of the ECMAScript spec.