aurelia / cli

The Aurelia 1 command line tool. Use the CLI to create projects, scaffold components, and bundle your app for release.
MIT License
407 stars 134 forks source link

[RFC] Better way of handling environment files (config files) #1039

Open avrahamcool opened 5 years ago

avrahamcool commented 5 years ago

💬 RFC

I want to talk about handling variable that are environment specific in aurelia.

the way that we handle it now, is by having multiple json files in an environment folder, when we start a build process - one of those files is copied into the src folder, and gets bundled with the rest of the app. you can dictate witch file is copied by specifying the "--env" flag while building.

in those files, you can put whatever you want - so it's an easy way to have variables that differ between environments.

I see 2 different kind of variables that can go into those config files.

  1. build time variables: variables that affect the build - (e.g minifying the code, enabling/disabling logging, enabling/disabling sourcemap etc.). setting different values in those variables should result in different build output.
  2. run time variables: variable that affect the application - (e.g api url endpoints, api keys, ticket duration etc) setting different values in those variables should not affect the build output. one may change those values even after the build and expect the app to consider the new values. this is currently cannot be done because the config file is bundled along with the application. any change to the config must also come with a new build.

the current way of handling config files has another problems/limitations:

  1. it's annoying to have a file in the src folder - that should not be committed into the source control.
  2. TFS adds readlony attributes to all the files that he manages - so copying one of the config files work only once, the next time you try to build - the file cannot be overwritten because of the readonly flag. https://github.com/aurelia/cli/issues/1031

what can we do about this? how does other framework handle config files? can we have 2 sort of configs? one for build time variables? and another for run time variables? can we even have files that are left outside of the bundle for easy editing? can we skip the part where we copy the file into src?

avrahamcool commented 5 years ago

Maybe something like this?

https://robinraju.github.io/developer/2017-11-14-loading-external-config-in-angular

But better.. Obviously

3cp commented 5 years ago

@avrahamcool latest webpack setup addressed parts of this, it uses app-settings-loader to avoid coping env file.