ember-env-macros
TypeScript icon, indicating that this package has built-in type declarations

0.3.2 • Public • Published

ember-env-macros

npm version Build Status

Get both build and runtime configurations in Ember app or addon.

Compatibility

  • Ember.js v3.4 or above
  • Ember CLI v2.13 or above
  • Node.js v8 or above

Installation

yarn add ember-env-macros

Usage

If you have build env:

// ember-cli-build.js
module.exports = function(defaults) {
  let app = new EmberAddon(defaults, {
    'some-config': {
      buildKey: true,
      nestedKey: {
        key: 'build',
      },
    },
  });
 
  return app.toTree();
};

and config env:

module.exports = function(environment) {
  let ENV = {
    // ...
    'some-config': {
      envKey: false,
      nestedKey: {
        key: 'config',
      },
    },
}

You can get access to them via:

import { configEnv, buildEnv } from 'ember-env-macros';
 
let model = {
  config: {
    envValue: configEnv('some-config.envKey'),
    nestedValue: configEnv('some-config.nestedKey.key'),
    defaultValue: configEnv('some-config.missingKey', 'default'),
  },
  build: {
    buildValue: buildEnv('some-config.buildKey'),
    nestedValue: buildEnv('some-config.nestedKey.key'),
    defaultValue: buildEnv('some-config.missingKey', 'default'),
  },
};

The build output will be:

var model = {
  config: {
    envValue: false,
    nestedValue: 'config',
    defaultValue: 'default',
  },
  build: {
    buildValue: true,
    nestedValue: 'build',
    defaultValue: 'default',
  },
};

When used in an addon or engine, both config and build envs are from the host app.

Contributing

See the Contributing guide for details.

License

This project is licensed under the MIT License.

/ember-env-macros/

    Package Sidebar

    Install

    npm i ember-env-macros

    Weekly Downloads

    40

    Version

    0.3.2

    License

    MIT

    Unpacked Size

    9.28 kB

    Total Files

    6

    Last publish

    Collaborators

    • xg-wang