This Transformer modifies code according to directives similar to those found in C preprocessors. The syntax should be familiar.
Let's start with an example:
_coreAjax = $['core-ajax']; // Get <core-ajax> element. /* #if DEBUG */ _coreAjax.url = "mock.json"; // Change actual prod URL to a mock file. /* #endif */
The URL-changing line will only be included in debug builds (which is also the
default mode for
pub serve). The line will not exist in release builds.
Since you can change build mode to any custom string by running
pub build --mode=<mode>, you can have things like this:
/* #if LOCALHOST */ baseUrl = "http://localhost/"; /* #endif */
pubspec.yaml, add simple_preprocessor as a dependency and as
a Transformer. Like this:
dependencies: simple_preprocessor: any ... transformers - simple_preprocessor
Try to include it before any other transformer (it's a pre-processor, after all).
This is not a best practice. You're changing semantics of your program by
a non-standard control mechanism that — worse still — lives in a comment. The
only thing that kind of makes this almost okay is that the
is so well recognized.
Even so, if you choose to use it, you shouldn't probably use it for anything
more than a few simple
#if DEBUG statements.
Currently, there's only
#if directive takes one argument, which must be all upper case. This will
be compared to the mode of
pub build ("release" by default) or
("debug" by default). When there's a match, anything between
#else) will be included. If not, it will be stripped.
#elif directive is on my TODO, but probably not anything else. This
shouldn't be a simplified programming language like that of a C preprocessor.
If you need to do something more complex than
#if DEBUG, you're better off
There is no
#define – the only definition is made by the transformer mode.
Sometimes, to play better with static analysis tooling, you might want to hide some of the lines from it. Here's a solution:
/* #if DEBUG *//* var speed = 1000; *//* #else */ var speed = 100; /* #endif */
Without the extra
*/, your IDE would probably display an error
about defining the
speed variable twice. But
identifies this syntax and will uncomment the contents between
for debug builds.
Note that the extra comment must come immediately after the
comment and directly before the
#endif comment. No whitespace is
Add this to your package's pubspec.yaml file:
dependencies: simple_preprocessor: ^0.0.3
You can install packages from the command line:
$ pub get
Alternatively, your editor might support
Check the docs for your editor to learn more.
Now in your Dart code, you can use:
|0.0.3||Feb 7, 2017|
|0.0.2||Nov 12, 2014|
|0.0.1||Nov 11, 2014|
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
The package version is not analyzed, because it does not support Dart 2. Until this is resolved, the package will receive a health and maintenance score of 0.
Fix dependencies in
pub upgrade failed with the following output:
ERR: The current Dart SDK version is 2.1.0. Because simple_preprocessor depends on barback >=0.6.2 which requires SDK version >=0.6.2 <2.0.0 or >=2.0.0-dev.17.0 <2.0.0, version solving failed.
dartfmt to format
dartfmt to format
Add SDK constraint in
pubspec.yaml. (-50 points)
For information about setting SDK constraint, please see https://www.dartlang.org/tools/pub/pubspec#sdk-constraints.
Fix platform conflicts. (-20 points)
Error(s) prevent platform classification:
Fix dependencies in
dartdoc failed. (-10 points)
dartdoc runs without any issues.
CHANGELOG.md. (-20 points)
Changelog entries help clients to follow the progress in your code.
Package is getting outdated. (-85.21 points)
The package was released 96 weeks ago.
Maintain an example. (-10 points)
Create a short demo in the
example/ directory to show how to use this package. Common file name patterns include:
example.dart or you could also use
Package is pre-v0.1 release. (-10 points)
While there is nothing inherently wrong with versions of
0.0.*, it usually means that the author is still experimenting with the general direction of the API.