Overriding existing configuration

To override some configs in your project, the process is simple and straight forward.

To illustrate this, we will take as example of overriding the javascript sources path directory. Note that the same process applies for any other configs as well...

Project (package) level overriding

  • Create the file .sugar/storage.config.js
  • Fill it like so

User level overriding

  • Create the file .local/.sugar/storage.config.js
  • Fill it like so

You'll see that the process is the same. The only difference is where are stored files. Note that the .local folder MUST be added in your .gitignore file if you're not using our development toolchain.

Config API and lazy values

Sometimes you will need to refer to an existing configuration like for example accessing the storage.package.rootDir value.

To do that, the safer way is to define your configuration like so:

.sugar/myConfig.config.ts

export default function(api) {
    return {
        get myConfigValue() {
            return `${api.config.storage.package.rootDir}/something`;
        }
}

You can see that an api object is accessible on the first argument of your config function. This first argument is an object containing these properties that you can use in your configs:

  • config: The global configuration object containing every registered configs.
  • env: An object containing some environment informations like:
    • env: The current environment like development, production, etc...
    • platform: The platform on which the config is running like browser or node.
    • target: The targeted environment in case of a "build" like development or production.
  • this: The current configuration. If you are in the frontendServer.config.ts file, this will be the complete frontentServer config object.
  • theme: The current theme configurations object
  • extends: A simple merge function (not recursive) if you need to.

You can also notice that your configuration value myConfigValue is defined using a getter. This is important to make sure your accessing code ${api.config.storage.package.rootDir}/something is executed only when the value is read. This avoid issues like accessing configs that are maybe not already loaded depending on the load order.

Bugs
are not our friends...

Don't hesitate to declare an issue if something does not works as expected.

Declare my issue on Github Talk about it on Discord

The more we are,
the stronger we become.

Don't hesitate to tell some words to you friends about us. The goal is to became more and more each days to help each others...

Support us on Patreon! Share on Facebook! Make a tweet!

The more we are,
the stronger we become.

Don't be afraid to join us on Discord.

Join us on discord!

We love,
Open source!

All of our codebase can be found on Github. We hope that you may contribute to help us make our tools even better!

Discover our codebase!

Welcome on