-
Notifications
You must be signed in to change notification settings - Fork 3
Dynamic Feature loading
The engine-scripts package allows running engine applications.
It locates all the source files required for running an engine feature (feature and environment files), bundles them for web environments, and then, when the feature is loaded in any one of the possible target, the feature and it's dependencies are being evaluated and loaded.
This article explains how it is possible to create and use features in a way that the used features are not part of the created bundle and it is up to the user of the engine application to decide whether to add them or not.
It is important to notice, the only difference between a "dynamic" feature and a regular feature is output of the build step of the application.
For building your feature to be consumed externally to a product, run npx engine build -f <featureName> --external.
When building with the flag --external provided, the -f/--feature flag should also be provided.
Important flag to notice:
--featureOutDir - when creating an external feature, an entry is created for each environment which imports the feature file.
When running in node environments, we need to know the location of the directory that contains the feature file, when the package is published (If you are using Typescript, for an example, the featureOutDir should be the outDir of tsc command).
Also, the following flags can be provided:
--withExternalFeatures - when flag is provided, a reference for the the external features that defined for that application (in engine.config.js) will be injected to the bundle, and the contents of these external features will be copied to the plugins folder.
--fetchExternalFeatures - when flag is provided, the web entry points of the application will fetch to /externals route to retrieve a list of all defined external features.
Next keys are available in the engine.config.js:
externalFeatureDefinitions: an array of objects, where each object may contain the following keys:
-
packageName(string): the name of the package of the external feature. -
outDir(string, optional): the directory where the built source code is located (default: dist). -
packagePath(string, optional): path to the package of the external feature (default: node_modules folder in the root of the application).
externalFeaturesPath: the path to the directory where the external features are located (default: node_modules folder in the root of the application).
serveExternalFeaturesPath: if false provided will not serve the externalFeaturesPath from the /external-features route.