如何使用dart2js将Dart

如何使用dart2js将Dart

本文介绍了如何使用dart2js将Dart Polymer应用程序部署到Javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Polymer到Javascript时部署Dart代码时遇到问题。我用DartEditor创建了一个聚合物应用程序,并做了一个简单的例子。这个例子在Dartium中工作,但是当我尝试将其构建为Polymer应用程序(在Javascript中)并启动它时,应用程序失败。

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.

Dart Polymer应用程序到Javascript?

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

这是我做的失败示例代码:

Here's the example code I made that fails :

example.html: / p>

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

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

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;
  }
}


推荐答案

add

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

到您的pubspec.yaml
并调用

to your pubspec.yamland call

pub build

您的文件应该在您的软件包的 web 目录中。

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

这篇关于如何使用dart2js将Dart Polymer应用程序部署到Javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 17:01