diff --git a/README.md b/README.md index f79ead8c..ae60554c 100644 --- a/README.md +++ b/README.md @@ -136,13 +136,13 @@ This project allows different configurations per environment. The files that man ``` ├─ src/config/ -| ├─ config.{ENVIRONMENT}.ts +| ├─ config.{NODE_ENV}.ts | └─ index.ts ``` -Before the build all the variables are shared between `index.ts` and `config.development.ts` but in the build process inside `rollup.config.js` the `import` of that last file is changed by the file related with the target environment following the rule `config.{ENVIRONMENT}.ts` and loading the expected configuration file. +Before the build all the variables are shared between `index.ts` and `config.development.ts` but in the build process the `import` of that last file is changed by the file related with the target environment following the rule `config.{NODE_ENV}.ts` and loading the expected configuration file. -Lastly, the way to use that configuration is quite simple. You only need to import it in your `.ts` file: +Lastly, the way to use that configuration is quite simple. You only need to import it: ```typescript import { config } from '../config'; diff --git a/rollup.config.js b/rollup.config.js index 7e36a5f4..229719cf 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -56,7 +56,10 @@ const config = merge( inlineSources: false }), replace({ - 'process.env.NODE_ENV': JSON.stringify('production'), + 'process.env.NODE_ENV': JSON.stringify('production') + }), + replace({ + include: 'src/config/index.ts', 'config.development': `config.${ENVIRONMENT}` }), copy({ diff --git a/src/config/config.development.ts b/src/config/config.development.ts index 0d3e3360..3c23ec59 100644 --- a/src/config/config.development.ts +++ b/src/config/config.development.ts @@ -5,6 +5,6 @@ * LICENSE file in the root directory of this source tree. */ -export const config = { +export default { environment: 'development' }; diff --git a/src/config/config.production.ts b/src/config/config.production.ts index 639d4749..4c88b116 100644 --- a/src/config/config.production.ts +++ b/src/config/config.production.ts @@ -5,6 +5,6 @@ * LICENSE file in the root directory of this source tree. */ -export const config = { +export default { environment: 'production' }; diff --git a/src/config/config.staging.ts b/src/config/config.staging.ts index 8c7557db..d5324616 100644 --- a/src/config/config.staging.ts +++ b/src/config/config.staging.ts @@ -5,6 +5,6 @@ * LICENSE file in the root directory of this source tree. */ -export const config = { +export default { environment: 'staging' }; diff --git a/src/config/index.ts b/src/config/index.ts index b110a8df..0dc0c4d1 100644 --- a/src/config/index.ts +++ b/src/config/index.ts @@ -5,14 +5,10 @@ * LICENSE file in the root directory of this source tree. */ -import { config as environmentConfig } from './config.development'; - -const sharedConfig = { - name: 'MyApplication', - description: 'MyApplication description' -}; +import environmentConfig from './config.development'; export const config = { - ...sharedConfig, + name: 'MyApplication', + description: 'MyApplication description', ...environmentConfig };