Dart:如何在调试和生产模式下使用不同的设置? [英] Dart: How to use different settings in debug and production mode?

查看:1550
本文介绍了Dart:如何在调试和生产模式下使用不同的设置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么想法如何设置我的Dart应用程序在调试模式(在Dartium中运行)和生产模式下使用不同的设置?

Are there any ideas how I can setup my Dart app to use different settings in debug mode (running in Dartium) and production mode?

m在我的应用程序中使用PouchDb,将数据库复制到特定的CouchDb实例,由一个url: db.replicateTo(url);
在调试模式下,我想使用另一个CouchDb实例(另一个url)比生产模式。

For example, I'm using PouchDb in my app, that replicates the database to a particular CouchDb instance, given by an url: db.replicateTo(url); In debug mode, I would like to use another CouchDb instance (another url) than in production mode.

因此,有没有任何想法或方法,在这两种模式下使用不同的设置?

So, are there any ideas or approaches, to use different setups in both modes?

推荐答案

这会在短时间内工作:

transformers: # or dev_transformers
- $dart2js:
  environment: { PROD: "true" }

String.fromEnvironment()

main() {
  print('PROD: ${const String.fromEnvironment('PROD')}'); 
  // works in the browser
  // prints 'PROD: null' in Dartium
  // prints 'PROD: true' in Chrome
}

另请参阅

  • Configuring the Built-in dart2js Transformer
  • How to achieve precompiler directive like functionality
  • https://github.com/dart-lang/pub/issues/798
  • http://blog.sethladd.com/2013/12/compile-time-dead-code-elimination-with.html
  • https://api.dartlang.org/stable/1.22.0/dart-core/bool/bool.fromEnvironment.html
  • dart check if is building

这篇关于Dart:如何在调试和生产模式下使用不同的设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆