Situation
I am currently in the process of migrating from Angular 4 and Angular Seed to Angular 6 and Angular CLI.
Challenge
One issue I am facing is with dynamic loading of plugins within a component using SystemJS.
SystemJS.import("client/plugins/" + this.pluginElement.type + "/" + this.pluginElement.type + ".js")
When running the application, I encountered the following error:
http://localhost/client/plugins/dapChart/dapChart.js 404 (Not Found)
This indicates that the js file is not present as an Asset.
Within the src/client/plugins folder, there are modules written in Typescript that can be utilized in the application.
I am seeking a solution to instruct Angular CLI to compile the plugins folder and treat the output as an asset, copying it directly into the dist folder.
Possibilities
I have considered three options, although I do not have concrete evidence on which one is optimal:
- Investigate how to customize the Angular-cli build https://codeburst.io/customizing-angular-cli-6-build-an-alternative-to-ng-eject-a48304cd3b21 However, being new to this, it may require a significant amount of time.
Manually compile the plugins folder and place it into a "pluginCompiled" directory, then declare it as Assets in Angular.json with
tsc -p src/client/plugins --outDir src/client/assets/plugins
This method involves stopping the server, compiling, and restarting ng serve each time, making it cumbersome.
- Create a sub project (workspace) in Angular.json specifically for compiling plugins and storing them in a "pluginCompiled" folder.
Inquiry
How can I include my transpiled plugins in the build output directory when using Angular 6 / Angular CLI?