Utilizing the typescript 2.4 [import()][1]
feature has proven to be effective for dynamically loading modules. Testing this functionality has shown positive results, especially when importing modules and components located within the same directory.
However, complications arose when attempting to deploy the project in production mode. Employing Angular-CLI
to build the project for production resulted in the generation of javascript
bundles, which presented challenges regarding module loading.
The project involves implementing a plugin-based architecture where users can seamlessly add different plugins as needed. These plugins are distinct from the main application and are intended to be loaded dynamically using the import()
method. Initially, the plugins were developed in typescript and could be loaded dynamically with ease. However, transitioning to production mode required converting the plugins into javascript
libraries that could still be imported using the import()
method.
To address this transition, the plugins were transformed into libraries utilizing https://github.com/jvandemo/generator-angular2-library. Upon attempting to import the index.js file, an error message was encountered:
"ERROR Error: Uncaught (in promise): Error: No NgModule metadata found for 'undefined'."
Below is the code snippet used for dynamically importing modules and components:
// Code for DynamicComponent class goes here
Example module and component files include:
data-widget.module.ts
@NgModule({
// Module configuration details
})
export class DataWidgetModule {
// Constructor and service registration details
}
data-widget.component:
@Component({
// Component configuration details
})
export class DataWidget{}
As the project progresses towards deployment in production mode, there is a need to overcome challenges related to loading external modules effectively. Any insights or solutions on how to achieve this would be greatly appreciated.