Quantcast
Viewing all articles
Browse latest Browse all 4828

Access ENV at build time (as opposed to runtime)

@gonvaled wrote:

I am running:

    » ember --version
    version: 1.13.13
    node: 0.12.2
    npm: 2.14.10
    os: linux x64

My application needs to be aware of the STATIC_URL where it is being deployed (which depends on the deploy environment "development" / "production") at two different stages:

  • when building the application, in order to use the right fingerprint prepend
  • on the client application, in order to prefix static assets with the right url

First I thought about defining a STATIC_URL variable on config/environment.js (where I have access to the environment parameter), and then do in ember-cli-build.js:

    // TODO: This does not work
    import config from './config/environment';

    module.exports = function(defaults) {
      var app = new EmberApp(defaults, {
        fingerprint: {
          enabled: true,
          prepend: config.STATIC_URL,
        },
      });
      return app.toTree();
    };

But I am unable to import the config environment:

import config from './config/environment';
^^^^^^
Unexpected reserved word

Probably what I am trying to do does not make much sense (passing values upwards from config/environment.js -> ember-cli-build.js). So instead of that, what I need is:

  1. Access the build environment parameter ("development" / "production") from ember-cli-build.js. This should be already available, since the ember-cli guide specifies that fingerprinting is by default only available in production: app.env === 'production'. But I need to access app.env before app is even defined. How to do that?
  2. Configure a STATIC_URL
  3. Pass the STATIC_URL parameter down to config/environment.js (to avoid reconfiguring it again for the client application)

How can I do 1 and 3?

Posts: 11

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 4828

Trending Articles