environment.production 变量在 app.module.ts 中始终为 true [英] environment.production variable always true inside app.module.ts
问题描述
我正在尝试在我的 app.module 文件中设置一个配置设置,以便根据我是否在生产中而有所不同.
我的 environment.ts
文件有
export const environment = {生产:假};
我的 environment.prod.ts
文件有
export const environment = {生产:真实};
在我的 app.module.ts
文件中,我正在尝试这样的事情
导入:[浏览器模块,应用路由模块,LoggerModule.forRoot({级别: (environment.production ? NgxLoggerLevel.OFF : NgxLoggerLevel.DEBUG)}),...
当我在任何地方执行 console.log(environment.production)
时,它告诉我这个值是 false
,因为我在开发环境中应该是这样.>
我的问题是它似乎在我的 app.module 文件中充当 true
.在这种情况下,我试图将我的日志语句设置为在生产环境中禁用,但它们在开发和生产中也被禁用.(如果我翻转我的条件语句,那么它们在开发和生产中都被启用).所以就好像它在读取 environment.production 不应该是真的.
能否在 app.module 中不能像这样使用 environment.production 变量,还是我在这里遗漏了其他东西?
我是直接在app.module.ts顶部直接导入生产版本
import { environment } from 'src/environments/environment.prod';
代替
import { environment } from 'src/environments/environment';
I am trying to set a config setting in my app.module file so that it's different depending on if I'm in production or not.
My environment.ts
file has
export const environment = {
production: false
};
My environment.prod.ts
file has
export const environment = {
production: true
};
In my app.module.ts
file I am attempting something like this
imports: [
BrowserModule,
AppRoutingModule,
LoggerModule.forRoot({
level: (environment.production ? NgxLoggerLevel.OFF : NgxLoggerLevel.DEBUG)
}),
...
When I do console.log(environment.production)
anywhere it tells me this value is false
as it should be while I am in the development environment.
My problem is that it seems to be acting as true
in my app.module file. I'm trying to set my log statements to be disabled on the production environment in this case, but they are also getting disabled in development and production. (If I flip my conditional statement then they get enabled in both dev and production). So it's as if it's reading environment.production to be true when it shouldn't be.
Can the environment.production variable not be used like this in app.module or am I missing something else here?
I was directly importing the production version directly at the top of app.module.ts
import { environment } from 'src/environments/environment.prod';
instead of
import { environment } from 'src/environments/environment';
这篇关于environment.production 变量在 app.module.ts 中始终为 true的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!