opinionated-config-parser
Select configuration for specific build target. If no target, defaults to process.env.NODE_ENV
.
- select an environment, mix (may overwrite) its data with the subfields of root;
- convert key name to format of
__OUT_DIR__
- return another copy for webpack 'DefinePlugin', which set them for client use;
example:
parseCfg(source, 'mock')
source
{
outDir:'dev'
publicPath:'/',
apiPath:'/api/'
targets:{
mock:{
publicPath:'/root/',
apiPath:'https://hna-app-test.hnair.com'
},
production:{
outDir:'dist',
publicPath:'/appname/',
apiPath:'https://hna-app-test.hnair.com',
}
}
}
output
{
__OUT_DIR__:'dev',
__PUBLIC_PATH__:'/root/',
__API_PATH__:'https://hna-app-test.hnair.com',
}
interface
Object
parseCfg(cfgInput, targetSelected, postProcessor) ⇒ Kind: global function
Returns: Object
- refer to @see
See: returned object
- cfg {Object} - merged config;
- stringifiedCfg {Object} - with strings processed with JSON.stringify;
- target {string} - calculated target;
Param | Type | Description |
---|---|---|
cfgInput | json |
content |
targetSelected | string |
selected target, subkey of 'targets'; |
postProcessor | Function |
process after selected config is merged before converting key character cases |
License
MIT.