最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to convert Dart to JavaScript? - Stack Overflow

programmeradmin5浏览0评论

The Dart app runs fine in Dartium, but I would like to convert it to JS.

C:\dart-sdk\bin\dart2js --out=test.js main.dart generates JS from:

import 'dart:html';

void main() {
  querySelector('#myid').text = 'Wake up, sleepy head!';
}

Then I add it to the <head>:

<!DOCTYPE html>
<html>
<head>
  <title></title>
  <script type="text/javascript" src="test.js"></script>
</head>
<body>
  <p id="myid">hello</p>
</body>
</html>

But when I run it in Firefox, it doesn't work. It shows only "Hello" on the page. What am I doing wrong?

The Dart app runs fine in Dartium, but I would like to convert it to JS.

C:\dart-sdk\bin\dart2js --out=test.js main.dart generates JS from:

import 'dart:html';

void main() {
  querySelector('#myid').text = 'Wake up, sleepy head!';
}

Then I add it to the <head>:

<!DOCTYPE html>
<html>
<head>
  <title></title>
  <script type="text/javascript" src="test.js"></script>
</head>
<body>
  <p id="myid">hello</p>
</body>
</html>

But when I run it in Firefox, it doesn't work. It shows only "Hello" on the page. What am I doing wrong?

Share Improve this question edited May 29, 2017 at 18:26 Badacadabra 8,5377 gold badges31 silver badges54 bronze badges asked Apr 27, 2015 at 19:58 SulimanSuliman 1,5093 gold badges13 silver badges19 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

dart2js is usually not the straight-forward way to generated JS from Dart. Normally you just run pub build in your project directory. Ensure you have your pubspec.yaml configured properly csp: true (for Chrome apps Using Polymer in a Dart Chrome App, Chrome App CSP violation after Dart/Polymer transform/pile to JavaScript)

发布评论

评论列表(0)

  1. 暂无评论