A simple dart transformer that removes content from files when building in release mode.
Add the dependency and transformer to your pubspec.yaml
:
dev_dependencies:
remove_transformer: ^1.0.0
transformers:
- remove_transformer
The order of the transformers determines the order they are run so remove_transformer
will most likely need to be toward the top. The transformer only runs in release
mode.
The transformer will remove content from files when it comes across the following strings.
remove:line
- removes the entire lineremove:start
/remove:end
- removes all lines fromremove:start
toremove:end
including the entirety of the start and end lines
String content = 'Debug content'; // remove:line
// remove:start
String str1 = 'Hello World';
String str2 = 'Goodnight Moon';
String str3 = 'err';
//remove:end
The following is an identical representation.
String str1 = 'Hello World'; // remove:start
String str2 = 'Goodnight Moon';
String str3 = 'err'; //remove:end
// remove:start
String mode = 'debug';
String greeting = 'Hello World';
// remove:end
/* remove:line
String mode = 'release';
String greeting = 'Hello';
remove:line */
or
// remove:start
String mode = 'debug';
String greeting = 'Hello World';
/* remove:end
String mode = 'release';
String greeting = 'Hello';
remove:line */
In debug
mode mode
and greeting
will have the values 'debug'
and 'Hello World'
.
In release
mode mode
and greeting
will have the values 'release'
and 'Hello'
.