Skip to content

Simple templating using config/environment.js at build time.

License

Notifications You must be signed in to change notification settings

StepicOrg/ember-cli-environment-config-replace

Repository files navigation

ember-cli-environment-config-replace

Simple templating using config/environment.js at build time.

Installation

ember install ember-cli-environment-config-replace

Usage

This addon looks for a @{PROP} pattern in files and replaces it with a PROP from environment/config.js at build time.

Nested properties are also supported, just use . as delimiter: @{PROP.A.B.C}.

Options and their defaults:

let app = new EmberApp(defaults, {
  'ember-cli-environment-config-replace': {
    enabled: true,

    // A list of files to parse in `/dist` directory.
    // NOTE: The replacement happens in the `postprocessTree` hook, 
    // so its essentially running once the files have already been processed.
    files: [
      'index.html',
      'tests/index.html',
    ],

    // Regex pattern for replacements.
    // The regex must have a group to capture property name.
    regex: /@\{\s?([\w-.]+)\s?\}/g
  }
});

If files is a function, it's passed the outputPaths object. It's better to rely on this rather than hard-coding file paths, because output paths for some assets can be configured in ember-cli.

'ember-cli-environment-config-replace': {
  files: outputPaths => [
    outputPaths.app.html,
    outputPaths.app.css.app,
  ]
}

Running tests

npm test