Environment-specific configurations via polymer.json #408

Open
cdata opened this Issue Sep 16, 2016 · 0 comments

Projects

None yet

1 participant

@cdata
Member
cdata commented Sep 16, 2016 edited

As a Polymer app author,
when I build my sharded application with polymer-cli,
I want to include a specialized environment configuration in the build output,
so that my app can adapt to being deployed to production.

Environment-specific Configurations

This is a design proposal for a new feature of the polymer build command.

Users can include an "environment" field in polymer.json that is a mapping of environment names to configurations. polymer build --env $envName can be used to select one of the configurations. Selecting a configuration causes that configuration to set as Polymer's configuration in the build artifact. So, if I have a polymer.json like:

{
  "entrypoint": "index.html",
  "shell": "src/foo-app/foo-app.html",
  "fragments": [
    "src/foo-app/fragment-one.html",
    "src/foo-app/fragment-two.html",
    "src/foo-app/fragment-three.html"
  ],
  "environment": {
    "production": {
      "lazyRegister": true,
      "custom": "foo"
    }
  }
}

And I run the CLI with polymer build --env production, I get a script tag added to my index that looks like:

<script>
window.Polymer = {
  lazyRegister: true,
  custom: "foo"
};
</script>

Alternative approach: configure global ENV property

One alternative approach would be to configure a global ENV property with the configuration values. This has the advantage of being more generalized, at the cost of requiring additional coordination in the main document. Assuming the above polymer.json is used, the polymer build --env production command would produce this script in the document:

<script>
<!-- NOTE: ENV name is just a strawman -->
window.ENV = window.ENV || {};
window.ENV.lazyRegister = true;
window.ENV.custom = 'foo';
</script>

Using this alternative approach, the same end result as the first design could be achieved with the following basic cooperation by the app author:

<script>
if (window.ENV) {
  window.Polymer = window.ENV;
}
</script>

Rationale

There is some precedence for this feature in other similar CLI tools:

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