How to deploy a Dart Polymer app to Javascript using dart2js

南楼画角 提交于 2019-12-21 19:46:23

问题


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:


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.



来源:https://stackoverflow.com/questions/20398157/how-to-deploy-a-dart-polymer-app-to-javascript-using-dart2js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!