opinionated-config-parser

1.1.6 • Public • Published

opinionated-config-parser

Build Status codecov Maintainability License

Select configuration for specific build target. If no target, defaults to process.env.NODE_ENV.

  1. select an environment, mix (may overwrite) its data with the subfields of root;
  2. convert key name to format of __OUT_DIR__
  3. 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

parseCfg(cfgInput, targetSelected, postProcessor) ⇒ Object

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.

Readme

Keywords

Package Sidebar

Install

npm i opinionated-config-parser

Weekly Downloads

1

Version

1.1.6

License

ISC

Unpacked Size

14.4 kB

Total Files

5

Last publish

Collaborators

  • roney