The project introduces the concept of "extensions".
Extension - is a reusable, isolated part of your application. It can contain presentation layer, business logic or even build configuration.
For NPM package to be considered an extension, it must have a
extension. For example:
The extensions are power-less without a theme. The application compiles from a theme sources. Extensions are just an isolated pieces, which make some features of your application work.
Any package containing the
@namespacemagic comments must have a
scandipwablock declared in its package.json file. Otherwise, the
@namespacemagic comments will not be handled correctly during the build time, hence will not work.
Both themes and extensions can register extensions. In order to do it, the extension should be added to
package.json. The extension must be a valid NPM package, therefore you are required to add it into
dependenciesfield of your
package.json. Like so:
This process could be automated using ScandiPWA CLI. First, make sure you are in your theme's root folder. Now, to install an extension from NPM registry, you can use following command:
scandipwa extension install <PACKAGE>
In order to create new extension, use following command:
scandipwa extension create <PACKAGE>
This command will create a new extension in the
packagesfolder and register it in your current theme. It will be symlinked from
packagesto proper folder under
Enabling and disabling an extension is achieved by setting the
falseas a value of the extension key in
scandipwa.extensions. Your theme can control enabled extensions across the whole application. This allows to disable the previously enabled extension. The sequence of preference in this case is:
- 1.Your theme enabled extensions
- 2.Your theme's parent themes enabled extensions
- 3.Extension enabled extensions
Extensions are very important and powerful part of ScandiPWA tool-chain. Following feature are available:
Following features are upcoming in next versions of Create ScandiPWA App releases:
- Translation bundles
- HTML template plugin