Wednesday, April 2, 2014

Giving Up on Single File Polymer.dart Transformers


Up today, I try to hack Polymer.dart, Dart Pub, and dart2js in the most horrible ways possible.

The end goal is to get a pub build of a Polymer element to produce a single deployment script. In its current incarnation, Polymer.dart's pub transformer produces 4 JavaScript files for deployment and it places the <polymer-element> templates directly in the transformed HTML:
<!DOCTYPE html><html lang="en">
<head>
<script src="packages/shadow_dom/shadow_dom.debug.js"></script>
<script src="packages/custom_element/custom-elements.debug.js"></script>
<script src="packages/browser/interop.js"></script>

    <!-- Load component(s) -->
    <!-- Load Polymer -->
    <script src="index.html_bootstrap.dart.js"></script>
</head>
<body>
<polymer-element name="x-pizza-toppings">
  <template><!-- ... --></template>
</polymer-element>
<polymer-element name="x-pizza">
  <template><!-- ... --></template>
</polymer-element>
    <div class="container">
      <h1>Ye Olde Dart Pizza Shoppe</h1>
      <x-pizza></x-pizza>
    </div>
</body></html>
In the previous days, I have managed to manually combine all of that (<polymer-template> and 4 JavaScript files) into a single JavaScript file for reusable deployment. I was unsuccessful in my efforts to write my own pub transformer, primarily because manual dart2js appears to ignore Polymer.dart annotations. If I cannot write my own transformer, I am going to hack as much of the default Polymer.dart transformer as possible to see if I can generate a single, deployable JavaScript file from my Polymer.dart code.

Except if I can't

It turns out that much of dart2js transformer code is, naturally enough, part of Dart's internals instead of Barback or Polymer.

I cannot use the Dart2JSTransformer from internal without compiling Dart from source, which… ugh. It's not that it's a ton of work—just a yak that I do not want to shave tonight for exploring Polymer. So I spend some time looking through the dart2js options that are used by the transformer in the hopes that I am missing some magical setting that would pick up my missing Polymer annotations.

In the end, however, I am unsuccessful. Bother. I think it best to drop this line of exploration for now. There are still a few other avenues of exploration that I need to tackle before Patterns in Polymer is finally done and this avenue is proving less and less fruitful. I will likely throw together a quick shell script tomorrow and then move on. Time permitting, I will return here and investigate compiler Dart so that I have more access to the internal libraries.


Day #22

No comments:

Post a Comment