@coffeekraken/s-sugar-config
Powerful config management class that let you access the .config.(j|t)s files stored either at (mono)repo, package (.sugar/) or user (.local/.sugar/) level.
Install
npm i @coffeekraken/s-sugar-config
SSugarConfig
This package expose a simple SSugarConfig
class that let you access the configurations from the sugar packages, as well as your own configs defined in your .sugar
folder.
Features
Node usage
Using it in node is as simple as importing the class, loading the configs and access them:
import __SSugarConfig from '@coffeekraken/s-sugar-config';
await __SSugarConfig.load();
const jsDir = __SSugarConfig.get('storage.package.src.jsDir');
Note that in a sugar CLI based process, the configuration loading is made for your in the CLI itself.
Browser usage
To use the sugar configs in your browser, you MUST either use the @coffeekraken/s-vite build, or inject the configs by yourself in your bundle see more.
The sugar config class admit that your configurations are stored under the window.env.SUGAR.config
object.
import __SSugarConfig from '@coffeekraken/s-sugar-config';
const fontawesomeConfig = __SSugarConfig.get('icons.fontawesome');
Note that you can obviously choose which configurations are exposed in your frontend code. Here's a simple example:
myConfig.config.ts
export default function (env, config) {
if (env.platform !== 'node') return;
return {
myConfig: 'hello',
};
}
Inject config
If you do not use the @coffeekraken/s-vite build, you can inject them like so:
Using vite
Make use of the @coffeekraken/s-vite-sugar-plugin vite plugin.
Injecting the configuration by yourself
The configurations MUST be stored in the window.env.SUGAR.config
object.
Here's a simple code that you can inject:
if (!window.env) window.env = {};
if (!window.env.SUGAR) window.env.SUGAR = {};
window.env.SUGAR.config = JSON.parse('your configs...');
API
Node
For more information about the Node API, please check out the API documentation
JS
For more information about the JS API, please check out the API documentation
License
Distributed under the MIT License. See LICENSE for more information.
Contact
Here's all the ways you can contact us listed: