Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add vars from external config files #1576

Closed
wants to merge 1 commit into from

Conversation

elvismacak
Copy link

  • What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
    Feature
    Help it easier to add new variables in code and different environments, make use of the webpack DefinePlugin

  • What is the current behavior? (You can also link to an open issue here)
    Consider my case:
    When I want to add a new config, like Google Analytics token, they should be different in development/test/production mode. (I think it would be better to add it into DefinePlugin)
    So first I add GA_TOKEN to each webpack.*.js's DefinePlugin:

      new DefinePlugin({
        'ENV': JSON.stringify(METADATA.ENV),
        'HMR': METADATA.HMR,
+        'GA_TOKEN': 'this is a setting in dev',
        'process.env': {
          'ENV': JSON.stringify(METADATA.ENV),
          'NODE_ENV': JSON.stringify(METADATA.ENV),
          'HMR': METADATA.HMR,
        }
      }),

And then add it into custom-typings.d.ts:

declare var GA_TOKEN: string;

Finally, I can use the GA_TOKEN in my ts code, like the ENV variable which already defined and declared.

When my settings getting growth, like PAYMENT_TOKEN, BACKEND_SERVER, thus coding style gets explosion.

  • What is the new behavior (if this is a feature change)?

Just simply define a GA_TOKEN in the config/vars/development.js and config/vars/prod.js, and easily use VARS.GA_TOKEN in your ts code.
No other configs need to be changed.

  • Other information:

While export all the config out into a single file, it would make it easier to be encrypt and generated

@PatrickJS
Copy link
Owner

interesting. I might end up going down this route

@PatrickJS
Copy link
Owner

I'm going to redo this and most likely go with something similar to what you did

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants