Webpack code splitting
This section presents a solution for using Webpack code splitting for deploying the application fragments.
What is Webpack code splitting?
Webpack code splitting allows generating bundles for JavaScript modules imported with the import() syntax. More information on this technique can be found here https://webpack.js.org/guides/code-splitting/#dynamic-imports .
Webpack and Angular
Webpack is used in Angular workspaces by default (see https://angular.io/cli/build) so no additional dependencies are required.
Solution in Angular
The solution is to use Webpack code splitting by generating potential imports (import() https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import) for each module project.
This will be accomplished by identifying projects inside a Silverlight solution that are either:
Silverlight application projects that reference PRISM and are actual applications.
Silverlight application projects that are meant to be modules to be loaded via XAP files
Given this separation the conversion tool is going to perform the following tasks:
Change all application projects meant to be XAP modules to library projects.
Generate a special file in Silverlight PRISM application projects that contains "import()" statements for each of the XAP modules.
This is going to have the effect of generating separate bundles for dynamically generated files.
Example
To illustrate how this is going to work, imagine a solution with the following structure:
This solution has:
An application project with the bootstrapper (BasicPrismModulesExperiment.csproj).
Two application projects meant to be XAP modules (MyExtraModule1.csproj and MyExtraModule2.csproj).
A PCL with some code (MyUtilityClassLib.csproj).
The conversion tool is going to analyze the application and try to make the separation listed above. The biggest challenge is to determine which Silverlight application is going to be a XAP module (more on this below). We assume that this is resolved then the conversion tool is going to treat: "MyExtraModule1.csproj" and "MyExtraModule2.csproj" as library projects.

The project that is determined to be the application project is going to have the following extra file:
As described above having import() expressions is going to "automagically" generate separate bundles for "MyExtraModule1" and "MyExtraModule2". See the output of "ng build":
Notice that a couple of new "chunks" are generated for the new modules.
Having this separation allows use to write a implementation of "AddModule":
Notice that framework uses TSyringe to create an instance of the module.
Having this conversion, the framework can execute the following registration code (this is the conversion of this example):
This code will be loaded separately:

Last updated
Was this helpful?