Giter VIP home page Giter VIP logo

angular-umd-dynamic-example's Introduction

Angular Dynamic UMD Module Loading

With the use of Angular 6 and the library support of the Angular CLI I've created this repository to provide a (one of many) solution to the dynamic module loading during run-time.

One of the sources guiding me can be found here; https://github.com/kirjs/angular-dynamic-module-loading.

How to start

Clone or download this repository;

git clone https://github.com/lmeijdam/angular-umd-dynamic-example

Navigate to the folder and install all dependencies;

npm install

By default I've added the UMD bundles from ModuleA, ModuleB, ModuleC and ModuleD. Also modules A and C are registered by default. This means they will get loaded when the app gets initialized.

Updating a module/library

When you want to make updates to one of the existing modules you can just update the source files in 'projects/(moduletoedit)/src/lib' and rebuilding that specific module with the Angular CLI;

ng build (module/libraryName)

After build you're able to replace the contents of that module in the 'assets' folder in either the dist folder or on the hosted environment. If you've added new dependencies like third party libraries and want to use them in the library. Make sure to update the 'modules' array in the module.service.ts and recompile.

Adding a new module/library

When you want to add a new library/module please make use of the Angular CLI command;

ng generate library (libraryName)

Edit the modules.json file with the correct module information and also make sure to have the RouterModule.forChild([]) configuration done in the module of the library.

In the original source you'll find an example to load up component dynamically and instantiate them in a ViewChild instead of extending the Router.

Now build the module with

ng build LibraryName

and copy the umd bundle to the 'assets' folder.

AOT and SystemJS

The app now supports AOT compilation by typing;

ng build --aot

Next to that I've changed the use of eval to the use of SystemJS to load the modules.

Running the application

For the application I've used https://www.npmjs.com/package/http-server which let your application run on port 8080 by default. After install you're able to run this application locally

npm install -g http-server

http-server ./dist/angular-dynamic-demo

Notes

angular-umd-dynamic-example's People

Contributors

lmeijdam avatar

Watchers

James Cloos avatar Pranav Jogawade avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.