From e41e2d70daf6dd48722f7f80e9fa3dc5d4dc98dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abdo=CC=81n=20Rodri=CC=81guez=20Davila?= Date: Thu, 3 Dec 2020 16:15:50 +0100 Subject: [PATCH 1/4] Update config readme --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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'; From 91e7f71502a3028b8c485b2779c880fbd923c0e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abdo=CC=81n=20Rodri=CC=81guez=20Davila?= Date: Thu, 3 Dec 2020 16:15:56 +0100 Subject: [PATCH 2/4] Be more specific with config replacement --- rollup.config.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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({ From 6c65f0e6920a773553ea7a96ec3dd0e02a121369 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abdo=CC=81n=20Rodri=CC=81guez=20Davila?= Date: Thu, 3 Dec 2020 16:12:26 +0100 Subject: [PATCH 3/4] Use default export for the configs --- src/config/config.development.ts | 2 +- src/config/config.production.ts | 2 +- src/config/config.staging.ts | 2 +- src/config/index.ts | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) 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..b48f69f3 100644 --- a/src/config/index.ts +++ b/src/config/index.ts @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -import { config as environmentConfig } from './config.development'; +import environmentConfig from './config.development'; const sharedConfig = { name: 'MyApplication', From d26e3f78d4782c0193dd4f9076bd8bc7d080203e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abdo=CC=81n=20Rodri=CC=81guez=20Davila?= Date: Thu, 3 Dec 2020 16:29:22 +0100 Subject: [PATCH 4/4] Inline shared config --- src/config/index.ts | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/config/index.ts b/src/config/index.ts index b48f69f3..0dc0c4d1 100644 --- a/src/config/index.ts +++ b/src/config/index.ts @@ -7,12 +7,8 @@ import environmentConfig from './config.development'; -const sharedConfig = { - name: 'MyApplication', - description: 'MyApplication description' -}; - export const config = { - ...sharedConfig, + name: 'MyApplication', + description: 'MyApplication description', ...environmentConfig };