Since a compilation is required before launching a dart application, i wonder if compiler preprocessor is available, or is scheduled in a near future for Dart.
My search
From http://blog.sethladd.com/2013/12/compile-time-dead-code-elimination-with.html
Suppose you have code like this:
log(String msg) {
if (const String.fromEnvironment('DEBUG') != null) {
print('debug: $msg');
}
}
main() {
log('In production, I do not exist');
}
When compiled with dart2js -DDEBUG=true app.dart
, the output includes the logging behavior:
main: function() {
H.printString("debug: In the production release, I do not exist");
}
(the log function is inlined, but the print still happens)
However, if -DDEBUG is not set, the logging behavior is not included in the generated JavaScript code:
main: function() {
}