Enable or disable an extension

An ability to control which extensions are active in your application, and which are not

Registering an extension

Both themes and extensions can register extensions. In order to do it, the extension should be added to mosaic.extensions object of package.json . The extension must be a valid NPM package, therefore you are required to add it into dependencies field of your package.json.

Enabling and disabling an extension is achieved by setting the trueor false as a value of the extension's key in mosaic.extensions .

Your theme can also 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's enabled extensions

  2. Your theme's parent themes' enabled extensions

  3. Extensions' enabled extensions

./package.json
{
    "dependencies": {
        "@example/enabled-package": "0.0.1",
        "@example/disabled-package": "file:./packages/@example/disabled-package"
    }
    "mosaic": {
        "extensions": {
            "@example/enabled-package": true,
            "@example/disabled-package": false
        }
    }
}

Watch out!

Disabling a previously enabled extension can lead to layout-shifts and issues inside of your parent theme. Also, there might be extensions plugging into the extension you intend to disable, this can lead to unexpected results.

Last updated