Skip to content
This repository has been archived by the owner on May 31, 2024. It is now read-only.

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 + 6c65f0e commit f964523
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 8 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
* LICENSE file in the root directory of this source tree.
*/

export const config = {
export default {
environment: 'staging'
};
2 changes: 1 addition & 1 deletion src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit f964523

Please sign in to comment.