4

I got a problem while deploying Dart code using Polymer to Javascript. I've created a polymer application with DartEditor and made a simple example. This example works in Dartium but when I try to build it as a Polymer App (in Javascript) and launch it, the app fails.

How am I supposed to convert a Dart Polymer app to Javascript ?

Here's the example code I made that fails :

example.html :

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Example</title>

    <link rel="import" href="example-polymer.html">
    <script type="application/dart">export 'package:polymer/init.dart';</script>
    <script src="packages/browser/dart.js"></script>
  </head>
  <body>
      <div is="example-polymer"></div>
  </body>
</html>

example-polymer.html

<polymer-element name="example-polymer" extends="div">
  <template>
    <div>
      <input on-change="{{ change }}"/><br>
      <span>Text : {{ text }}</span>
    </div>
  </template>
  <script type="application/dart" src="example-polymer.dart"></script>
</polymer-element>

example-polymer.dart

import 'package:polymer/polymer.dart';
import 'dart:html';

@CustomTag('example-polymer')
class ExampleBolymer extends DivElement with Polymer, Observable {
  @published String text = "" ;

  ExampleBolymer.created() : super.created() {
  }

  void change(Event e, var detail , InputElement target) {
    text = target.value;
  }
}

1 Answer 1

6

add

transformers:
- polymer:
    entry_points:
    - web/example.html

to your pubspec.yaml and call

pub build

Your files should be in the web directory of your package.

Sign up to request clarification or add additional context in comments.

3 Comments

It is "generating" files to "out" directory. And after compiling to JS, it still doesn't work :(
Did you run it from the DartEditor or did you run dart2js? AFAIK DartEditor's menues to start dart2js are not up-to-date (WIP). I had the best experience calling pub build or pub build --mode=debug in the command line in the package root directory.
I think this is a known problem. pub build fails if you have files in you web directory from a previous run as JavaScript like that with the extension .bootstrap.dart. Please remove all generated files form your web directory or the entire web/out directory if it exists and run pub build again.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.