Node config loader
Scan directories, load, parse to js object and merge many configs into single file/object.
- Highly customizable and composable: each component is a pure function and exposed to public: compose you own loaders
- Used globby for files matching
- Compatible with lorenwest node-config file loading scheme, but each file name can be prefixed by '#' separator
- Default loader supports json and yml files via nodeca js-yaml (can be overrided)
- Live reload support via webpack loader
Config merge example
# input1#dev.yaml ns: to: name: testtestArr: - t1 - t2__push__: [testArray2]testArray2: - test1 - test2
# input2#dev.yaml ns: to: email: test-emailtestArr: - t3testArray2: - test3
merged input1 + input2:
#output.yaml ns: to: name: test email: test-emailtestArr: - t3testArray2: - test1 - test2 - test3
Usage
As common lib
//simple.js
As webpack loader
Config load order:
- .configloaderrc
- webpack.config.js configLoader section
- webpack loader query params
console
Where .configloaderrc is
mask is required, all other params are optional.
Available env vars in mask:
- {ROOT} - project root
- {DIRNAME} - .configloaderrc directory
- {PWD} - process.cwd()
- any process.env variable
Via Webpack config
// webpack.config.jsmoduleexports = plugins: options: configLoader: env: isProduction ? 'prod' : 'dev' instance: processenvAPP_INSTANCE || 'client' module: loaders: test: /.*\.configloaderrc$/ loader: 'node-config-loader/webpack'
Flowtype
npm install --save empty
.flowconfig
[options]module.name_mapper='.*\(\.configloaderrc\)' -> 'empty/object'
Isomorphic friendly сlient with run-time config
// getConfig.js { return env: origin: locationorigin hash: locationhash pathname: locationpathname search: locationsearch referrer: referrer config: debug: settingsdebug sitePrefix: settingssitePrefix locale: lang: settingslocale } { return }
// index.js const config = // config
interfaces
// @flow : Objectfunction strMap(strs: string, templateArgs: {id: string: string}): string interface CreateScannerOpts merge?: Object; parser?: Promise<Object>; readFile?: Promise<Buffer>; type Promise<Object> : Scanner interface CreateNodeFilterOpts { instance?: string; hostname?: string; tagSeparator?: string; env?: string; templates?: string;}: (files: string[]) => string[] interface GetFilesOptions extends CreateNodeFilterOpts { mask: string; glob?: cwd?: string; root?: string; dot?: string; nomount?: boolean; mark?: boolean; nosort?: boolean; stat?: boolean; readdir?: boolean; silent?: boolean; statCache?: Object; symlinks?: Object; debug?: boolean; nonull?: boolean; nounique?: boolean; nobrace?: boolean; noglobstar?: boolean; noext?: boolean; nocase?: boolean; matchBase?: boolean; nodir?: boolean; ignore?: string; follow?: boolean; realpath?: boolean; absolute?: boolean; }: Promise<string[]>; interface LoadConfigOptions extends GetFilesOptions, CreateScannerOpts { mask: string; instance?: string; hostname?: string; tagSeparator?: string; env?: string; templates?: string; glob?: Object; merge?: Object; parser?: Promise<Object>; readFile?: Promise<Buffer>;}: Promise<Object>