add vars from external config files #1576
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 eachwebpack.*.js
's DefinePlugin:And then add it into
custom-typings.d.ts
: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.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.
While export all the config out into a single file, it would make it easier to be encrypt and generated