Examples of Transformer Code

Send feedback

When pub serves, builds, or runs an app, it can run one or more transformers. (Learn more about pub.)

Transformers operate on assets, where an asset is a resource, such as a Dart file, a CSS file, or an image, that is intended to be part of a deployed package. (Learn more about assets and transformers.)

The following are examples of custom transformers written using the barback package. The description for each example states where you can get more information about that particular example.

aggregate_transformer
Combines partial HTML files contained in a “recipes” directory into a single HTML file. See Writing an Aggregate Transformer for more information.
lazy_transformer
Lazily converts a text file using a ROT13 converter. See Writing a Lazy Transformer for more information.
markdown_converter
Converts a markdown file (with either a “.mdown”, “.md”, or a “.markdown” extension) to HTML. The output asset has an “.html” extension. See Writing a Pub Transformer for more information.
simple_transformer
Inserts a copyright string at the beginning of a “.txt” file. See Writing a Pub Transformer for more information.

All of these examples are part of the barback repo on GitHub.

To run an example, first clone or download the barback repo. Then under the example/example_name directory, create an empty web directory, and run pub build to generate the assets. Pub transforms the sample assets (located in lib) and places them under build.