说这是我的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
这就是我所看到的
请注意,应用程序名称已被删除。
但是检查全局对象有效吗?
console.log(ApplicationName.API_HOST);
现在我不想访问全局对象,因为它有点像hacky。它是2017年,我们现在有模块......
:/
答案 0 :(得分:0)
当ember-cli构建你的应用程序时,它会在HTML中的元字段中对配置对象进行编码,如果你有一个服务工作者提取index.html并缓存它,当你更新你的{{1}时它将进入一个新的index.html
可以防止您看到更改的一件事是当您的服务工作者缓存您的index.html时,这就是我遇到的问题。
答案 1 :(得分:0)
我注意到您在test
环境中添加了值。只需将它们移动到development
环境。