All Projects → Quramy → Angular2 Load Children Loader

Quramy / Angular2 Load Children Loader

Licence: mit
A webpack loader for ng2 lazy loading

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Angular2 Load Children Loader

Openrouteservice
🌍 The open source route planner api with plenty of features.
Stars: ✭ 614 (+2569.57%)
Mutual labels:  routing
Clash Rules
🦄️ 🎃 👻 Clash Premium 规则集(RULE-SET),兼容 ClashX Pro、Clash for Windows 客户端。
Stars: ✭ 706 (+2969.57%)
Mutual labels:  routing
Inline Style Loader
inline style loader for webpack
Stars: ✭ 16 (-30.43%)
Mutual labels:  webpack-loader
Awesome Nextjs
📔 📚 A curated list of awesome resources : books, videos, articles about using Next.js (A minimalistic framework for universal server-rendered React applications)
Stars: ✭ 6,812 (+29517.39%)
Mutual labels:  routing
Bundle Loader
Bundle Loader
Stars: ✭ 666 (+2795.65%)
Mutual labels:  webpack-loader
Pgrouting
Repository contains pgRouting library. Development branch is "develop", stable branch is "master"
Stars: ✭ 804 (+3395.65%)
Mutual labels:  routing
React Svg Loader
A loader for webpack, rollup, babel that loads svg as a React Component
Stars: ✭ 570 (+2378.26%)
Mutual labels:  webpack-loader
Reitit
A fast data-driven router for Clojure/Script
Stars: ✭ 892 (+3778.26%)
Mutual labels:  routing
Openmessaging Java
OpenMessaging Runtime Interface for Java
Stars: ✭ 685 (+2878.26%)
Mutual labels:  routing
Node Config Loader
Scan directories and loads config json and yaml files
Stars: ✭ 5 (-78.26%)
Mutual labels:  webpack-loader
Jlroutes
URL routing library for iOS with a simple block-based API
Stars: ✭ 5,528 (+23934.78%)
Mutual labels:  routing
Router
A lightweight and simple object oriented PHP Router
Stars: ✭ 633 (+2652.17%)
Mutual labels:  routing
I18n Module
i18n for Nuxt
Stars: ✭ 808 (+3413.04%)
Mutual labels:  routing
Micro Router
🚉 A tiny and functional router for Zeit's Micro
Stars: ✭ 621 (+2600%)
Mutual labels:  routing
Node Addon Loader
A loader for node native addons
Stars: ✭ 17 (-26.09%)
Mutual labels:  webpack-loader
Wasm Loader
✨ WASM webpack loader
Stars: ✭ 604 (+2526.09%)
Mutual labels:  webpack-loader
Raw Loader
A loader for webpack that allows importing files as a String
Stars: ✭ 800 (+3378.26%)
Mutual labels:  webpack-loader
Storeon Async Router
Asynchronous router for Storeon. It provides possibility for prefetch the data, lazy load, navigation cancellation, and routes modification on the fly.
Stars: ✭ 22 (-4.35%)
Mutual labels:  routing
Nunjucks Isomorphic Loader
Nunjucks loader for webpack, supporting both javascript templating and generating static HTML files through the HtmlWebpackPlugin.
Stars: ✭ 17 (-26.09%)
Mutual labels:  webpack-loader
Zeps Gui
L'interface d'un outil de calcul d'itinéraires, principalement utilisé pour se repérer dans le Netherrail de Zcraft. Nécessite https://github.com/zDevelopers/ZePS-Core .
Stars: ✭ 5 (-78.26%)
Mutual labels:  routing

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

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