`application-name / config / environment`的`APP`属性中缺少的属性

时间:2017-04-05 06:44:02

标签: ember.js ember-cli

说这是我的application-name/config/environment

/* jshint node: true */

module.exports = function(environment) {
  var ENV = {
    modulePrefix: 'app-name',
    environment: environment,
    rootURL: '/',
    locationType: 'auto',

    pageTitle: {
      separator: ' - ',
      // we want to append the nested title as suffix
      prepend: false,
      // replace completely replaces the outer title we don't want that
      replace: false,
    },

    EmberENV: {
      FEATURES: {
        // Here you can enable experimental features on an ember canary build
        // e.g. 'with-controller': true
      },
      EXTEND_PROTOTYPES: {
        // Prevent Ember Data from overriding Date.parse.
        Date: false
      }
    },

    APP: {
      // Here you can pass flags/options to your application instance
      // when it is created
    },

    i18n: {
      defaultLocale: 'en',
    },
  };

  if (environment === 'test') {
    // Testem prefers this...
    ENV.locationType = 'none';

    // keep test console output quieter
    ENV.APP.LOG_ACTIVE_GENERATION = false;
    ENV.APP.LOG_VIEW_LOOKUPS = false;

    ENV.APP.rootElement = '#ember-testing';
    ENV.APP.API_HOST = 'http://dev.api.appname.com';
  }
  else if (environment === 'production') {

  }
  else {
    ENV.APP.API_HOST = 'http://dev.api.appname.com';
  }

  return ENV;
};
  

它几乎是默认生成的一个,除了dev&中的API_HOST子属性中有APP。测试模式。

在随机模块中说我这样做

import ENV from 'application-name/config/environment';
console.log(ENV.APP.API_HOST); 

我期望的是.APP.API_HOST中记录的值,除非我看到未定义...如果我记录ENV.APP这就是我所看到的

enter image description here

  

请注意,应用程序名称已被删除。

但是检查全局对象有效吗?

console.log(ApplicationName.API_HOST);

现在我不想访问全局对象,因为它有点像hacky。它是2017年,我们现在有模块......

我尝试了什么

  1. 确保我使用了合适的环境,我们还没有尝试过,因为我们没有生产产品......
  2. This specific plugin,只是为了得到相同的结果
  3. 我确实在Ember松弛的帮助频道上提出了这个问题,但我在那里取得了那么大的成功:/

2 个答案:

答案 0 :(得分:0)

当ember-cli构建你的应用程序时,它会在HTML中的元字段中对配置对象进行编码,如果你有一个服务工作者提取index.html并缓存它,当你更新你的{{1}时它将进入一个新的index.html

可以防止您看到更改的一件事是当您的服务工作者缓存您的index.html时,这就是我遇到的问题。

答案 1 :(得分:0)

我注意到您在test环境中添加了值。只需将它们移动到development环境。