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 likedevelopment
,production
, etc...platform
: The platform on which the config is running likebrowser
ornode
.target
: The targeted environment in case of a "build" likedevelopment
orproduction
.
this
: The current configuration. If you are in thefrontendServer.config.ts
file, this will be the completefrontentServer
config object.theme
: The current theme configurations objectextends
: A simplemerge
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.