Skip to content

Commit

Permalink
Merge branch 'config' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
abdonrd committed Dec 3, 2020
2 parents 6ae5e8c + d26e3f7 commit 952f677
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 14 deletions.
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -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';
Expand Down
5 changes: 4 additions & 1 deletion rollup.config.js
Expand Up @@ -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({
Expand Down
2 changes: 1 addition & 1 deletion src/config/config.development.ts
Expand Up @@ -5,6 +5,6 @@
* LICENSE file in the root directory of this source tree.
*/

export const config = {
export default {
environment: 'development'
};
2 changes: 1 addition & 1 deletion src/config/config.production.ts
Expand Up @@ -5,6 +5,6 @@
* LICENSE file in the root directory of this source tree.
*/

export const config = {
export default {
environment: 'production'
};
2 changes: 1 addition & 1 deletion src/config/config.staging.ts
Expand Up @@ -5,6 +5,6 @@
* LICENSE file in the root directory of this source tree.
*/

export const config = {
export default {
environment: 'staging'
};
10 changes: 3 additions & 7 deletions src/config/index.ts
Expand Up @@ -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
};

0 comments on commit 952f677

Please sign in to comment.