Last active
August 23, 2017 18:48
-
-
Save starstuffharvestingstarlight/b41ff3cc4aeacecef55e0bcb6981e78f to your computer and use it in GitHub Desktop.
Environment inheritance example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export class BaseEnvironment { | |
| env: BaseEnvironment.Env | |
| FirebaseConfig: { | |
| apiKey: string, | |
| authDomain: string, | |
| databaseURL: string, | |
| projectId: string, | |
| storageBucket: string, | |
| messagingSenderId: string | |
| } | |
| myOtherSetting: { | |
| someNumber: number, | |
| someConstrainedString: 'val1' | 'val2' | 'val3' | |
| } | |
| } | |
| export module BaseEnvironment { | |
| export enum Env { | |
| Dev, | |
| Stage, | |
| Prod, | |
| QA | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { BaseEnvironment } from './BaseEnvironment' | |
| class DevEnvironment extends BaseEnvironment { | |
| env = BaseEnvironment.Env.Dev | |
| FirebaseConfig = { | |
| apiKey: "somekey", | |
| authDomain: "somedomain", | |
| databaseURL: "somedb", | |
| projectId: "someid", | |
| storageBucket: "somebucket", | |
| messagingSenderId: "somemessageid" | |
| } | |
| myOtherSetting = { // These settings don't validate and will cause a compiler error | |
| someNumber: 'abc', | |
| someConstrainedString: 'value_not_in_list' | |
| } | |
| } | |
| export const Environment = new DevEnvironment() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { BaseEnvironment } from './BaseEnvironment' | |
| export const Environment = new BaseEnvironment() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var webpack = require('webpack') | |
| var merge = require('webpack-merge') | |
| var webpackConfig = require('../node_modules/@ionic/app-scripts/config/webpack.config') | |
| var environmentPath = /\/environment\/Environment$/ | |
| module.exports = merge(webpackConfig, { | |
| plugins: [ | |
| new webpack.EnvironmentPlugin({ | |
| ENVIRONMENT: undefined | |
| }), | |
| new webpack.NormalModuleReplacementPlugin(environmentPath, function (resource) { | |
| var env = process.env.ENVIRONMENT || 'dev' | |
| resource.request = resource.request.replace(environmentPath, '/environment/' + env.charAt(0).toUpperCase() + env.substring(1) + 'Environment'); | |
| }) | |
| ] | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment