Mantra official documentation

18-component-configuration.md

A  A  A 

Component Configuration

Each component can define a json object with its own specific configuration.

There are two places where to locate a component configuration:

  • Inside "ComponentsConfig" property in mantraconfig.json with the name of the component.
  • In the mantra.json file for the component in the property "defaultconfig".

As an example, consider this mantra.json file for the component "resourceminifier":

{
    "name": "Resource minifier component",
    "version": "1.0.0",
    "defaultconfig": {
        "minify": false,
        "obfuscate": false,
        "compactjsfiles": false,
        "compactcssfiles": false
    },
    "dependencies": ["files"]
}

The json property "defaultconfig" will be considered as the default configuration for the component; to overwrite this default configuration, then this json should be placed at "ComponentsConfig" property in the project configuration file mantraconfig.json:

{
    // ...
    "ComponentsConfig":
        "resourceminifier": {
            "minify": false,
            "obfuscate": false,
            "compactjsfiles": false,
            "compactcssfiles": false
    }
    // ...
}

With this capacity of overwritten the default component configuration, the component can be reused in other projects or adapt its behaviour for specific needs.

Accessing component configuration from Mantra API

There are two ways to access programatically to the configuration of a component:

const config = Mantra.GetComponentConfig("resourceminifier");
  • Get an specific value for the component configuration with the syntax "[name of the component].[property]" directly from Mantra API object with Config method:
const shouldMinify = Mantra.Config("resourceminifier.minify")

Components configuration can not be changed at run time.


To learn by example, go to Mantra demos and components sections of Mantra site.