项目作者: houfeng0923

项目描述 :
support global env const in js and hbs for ember app.
高级语言: JavaScript
项目地址: git://github.com/houfeng0923/ember-cli-global-env.git
创建时间: 2020-04-08T10:13:10Z
项目社区:https://github.com/houfeng0923/ember-cli-global-env

开源协议:MIT License

下载


ember-cli-global-env

support global env const in js and hbs for ember app.

Features

  • support js and hbs files
  • minify code in production mode

Compatibility

  • Ember.js v3.2 or above
  • Ember CLI v2.13 or above
  • Node.js v10 or above

Installation

  1. ember install ember-cli-global-env

Usage

By default, automatic import all APP-* variables in process.env, so you can use it directly;
otherwise, your can define extra const in config/global-env.js.

  1. // config/global-env.js
  2. module.exports = function (environment) {
  3. const flags = {
  4. CFX: process.env['APP_BRAND'] === 'cfx',
  5. Token: 'xxxxxx'
  6. };
  7. return flags;
  8. };

Additional options can be specified using the global-env config property in ember-cli-build.js:

  1. let app = new EmberApp({
  2. 'global-env': {...}
  3. });

Available Options:

  • helperName: default is env, a helper for access global env in template
  • importPath: default is @global/env, so you can import global env from this path

Example

hbs

source:

  1. {{env 'Token'}}
  2. {{#if (env 'CFX')}}
  3. <div>cfx template....</div>
  4. {{/if}}
  5. {{other-component}}

output (in building before opcode) :

  1. xxxxxx
  2. <div>cfx template....</div>
  3. {{other-component}}

js

source:

  1. import { CFX, Token } from '@global/env';
  2. export default class IndexRoute extends Route {
  3. init() {
  4. console.log(Token);
  5. if (!CFX) {
  6. console.log('cfx logic');
  7. }
  8. }
  9. }

output (in production mode)

  1. export default class IndexRoute extends Route {
  2. init() {
  3. console.log('xxxxxx');
  4. }
  5. }

Contributing

See the Contributing guide for details.

License

This project is licensed under the MIT License.