https://github.com/irustm/angular-plugins-ivy
Angular plugins Ivy, only webpack
https://github.com/irustm/angular-plugins-ivy
Last synced: 9 months ago
JSON representation
Angular plugins Ivy, only webpack
- Host: GitHub
- URL: https://github.com/irustm/angular-plugins-ivy
- Owner: irustm
- Created: 2019-05-23T17:28:40.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-07T05:44:38.000Z (almost 3 years ago)
- Last Synced: 2025-04-04T05:06:53.195Z (9 months ago)
- Language: TypeScript
- Size: 952 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 19
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Angular Plugins Ivy
This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 8.0.0-rc.4.
## webpack dynamic loader
```typescript
// dynamic import plugin
const load = plugin => import(`./${plugin}/${plugin}.module`);
declare const __webpack_require__: any;
// only specific webpack require ensure
const loaderModule: any = (id, src, mod) => __webpack_require__.e(id).then(el => __webpack_require__(src)[mod]);
// plugin = route
const loaderRouteModule = () => {
const config = plugins.find(p => p.route === location.pathname);
return loaderModule(config.chunk, config.src, config.name);
};
const routes: Routes = [
{
path: ':pluginId',
loadChildren: async () => {
return loaderRouteModule();
}
}
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }
```
Config
```typescript
const plugins = [
{
route: '/one',
chunk: 0,
src: './src/app/plugin-one/plugin-one.module.ts',
name: 'PluginOneModule',
},
{
route: '/two',
chunk: 1,
src: './src/app/plugin-two/plugin-two.module.ts',
name: 'PluginTwoModule',
}
];
```