This is a plugin that only has a peer dependency to
piral-lazy brings to the table is a set of Pilet API extensions that can be used with
The set includes a
By default, these API extensions are not integrated in
piral, so you'd need to add them to your Piral instance. We recommend integrating
piral-lazy when you think about an opt-in for any third-party framework (e.g.,
The following functions are brought to the Pilet API.
Allows to define lazy loading dependencies in form of lazy loading functions. This can be used to ensure certain data is available or that certain modules are already loaded.
A simple example:
Transforms the result of a promise derived from a callback (i.e., lazy loading) to a proper component. This is thought for non-React lazy loading. For React you'll need to use the known way of applying
React.lazy to your component initialization.
For authors of pilets
You can use the
fromLazy function from the Pilet API to convert your lazy loaded components to components usable by your Piral instance.
Remark: For React components
React.lazy should be preferred. The provided lazy loading wrapper should only be used for third-party components that require a converter.
For lazy loading externals we recommend a combination with import maps. These can be set up in package.json as simple as follows:
Now we can actually use this in combination with
Important: You'll either need to use import maps or
externals in your package.json to be able to use
import from in your lazy loaded bundles. Otherwise, the noted packages will be fixed bundled in. If you follow the setup above you'd be fine in any case.
The other use case could be population of data, e.g., in combination with a global state container:
// Lazy loaders;;.thenimport'./setstore'.thenm.defaultres;// Components;// Registrationsapp.defineDependency'common', common;app.defineDependency'prerequest', prerequest;app.registerPage'/translate', TranslatePage;
Setup and Bootstrapping
For Piral instance developers
Using lazy loading with Piral is as simple as installing
The integration looks like:
Piral is released using the MIT license. For more information see the license file.