title: How to auto run transformer on asset change
body: <p><a href="http://pub.dartlang.org/packages/barback" rel="nofollow noreferrer">Barback package</a> description:</p>
  
  <blockquote>
    <p>An asset build system. Given a set of input files and a set of
    transformations (think compilers, preprocessors and the like), will
    automatically apply the appropriate transforms and generate output
    files. <strong>When inputs are modified, automatically runs the transforms
    that are affected.</strong> Runs transforms asynchronously and in parallel when
    possible to maximize responsiveness.</p>
  </blockquote>
  
  <p><a href="https://www.dartlang.org/tools/pub/assets-and-transformers.html" rel="nofollow noreferrer">Docs on assets and transformers say:</a></p>
  
  <blockquote>
    <p>For pub serve, the transformers run when the dev server starts up and
    whenever a source asset changes. The pub build command runs the
    transformers once and then exits.</p>
  </blockquote>
  
  <p><a href="https://github.com/dart-lang/bleeding_edge/tree/master/dart/pkg/barback/example/markdown_converter" rel="nofollow noreferrer">So I took this example:</a>
  </p>
  
  <pre class="lang-dart prettyprint-override"><code>// Copyright (c) 2014, the Dart project authors.  Please see the AUTHORS file
  // for details. All rights reserved. Use of this source code is governed by a
  // BSD-style license that can be found in the LICENSE file.
  
  import 'package:barback/barback.dart';
  import 'package:markdown/markdown.dart';
  
  import 'dart:async';
  
  class ConvertMarkdown extends Transformer {
  
    // A constructor named "asPlugin" is required. It can be empty, but
    // it must be present. It is how pub determines that you want this
    // class to be publicly available as a loadable transformer plugin.
    ConvertMarkdown.asPlugin();
  
    // Any markdown file with one of the following extensions is
    // converted to HTML.
    String get allowedExtensions =&gt; ".md .markdown .mdown";
  
    Future apply(Transform transform) {
      return transform.primaryInput.readAsString().then((content) {
  
        // The extension of the output is changed to ".html".
        var id = transform.primaryInput.id.changeExtension(".html");
  
        String newContent = "&lt;html&gt;&lt;body&gt;"
                          + markdownToHtml(content)
                          + "&lt;/body&gt;&lt;/html&gt;";
        transform.addOutput(new Asset.fromString(id, newContent));
      });
    }
  }
  </code></pre>
  
  <p>It runs as expected with <code>pub build</code>, but does nothing with <code>pub serve</code> except printing: </p>
  
  <blockquote>
    <p>Build completed successfully</p>
  </blockquote>
  
  <p>every time I change any file (not only appropriate asset) in the directory.</p>
  
  <p><a href="https://stackoverflow.com/questions/24076347/infinite-file-watcher/24078858">After reading this</a> I think that Dart has some problems with watching files(not only directories) on Windows platform.</p>