飞镖检查如果是建设 [英] dart check if is building

查看:155
本文介绍了飞镖检查如果是建设的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想跳过一些关于pub build的特定代码。

I would like to skip some specific code on pub build.

例如:

Log.print('something $ {StackTrace.current}');

Log.print('something ${StackTrace.current}');

我想上面的代码没有在生产中传递给JS。

I would like that the code above was not transpilled to JS in production.

推荐答案

p> Asserts仅在检查模式下执行,并且在生产模式下默认情况下不会包含 pub build

Asserts are only executed in checked mode and won't be included by pub build in production mode by default:

assert(() {
  Log.print('something ${StackTrace.current}');
  return true;
})

DartPad示例 无法打印,因为它是以生产模式构建的。

DartPad example doesn't print it because it builds in production mode.

您也可以传递environment混合使用OS环境变量)到 pub build 并在代码中读取

You can also pass "environment" (not mix up with OS environment variables) to pub build and read it in code

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





const prod = String.fromEnvironment('PROD')
print('PROD: $prod');
// prints 'PROD: null' in Dartium
// prints 'PROD: true' in Chrome

另请参见 http://stackoverflow.com/a/22524258/217408

这篇关于飞镖检查如果是建设的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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