Environment-specific configurations via polymer.json #408

cdata opened this Issue Sep 16, 2016 · 0 comments


None yet

1 participant

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": [
  "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:

window.Polymer = {
  lazyRegister: true,
  custom: "foo"

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:

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

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

if (window.ENV) {
  window.Polymer = window.ENV;


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