简体   繁体   中英

Test Dart and dart2js code in same page

I trying my luck on Dart. I've got an application that loads the Dart file and the generated Javascript:

<script type="application/dart" src="/bones/build/web/quiz/quiz1.dart">
</script>
<script src="/bones/build/web/quiz/quiz1.dart.js">
</script>

When I open this page in Dartium, both the Javascript and the Dart code are run (I only need one).
How do I go about to run only the Dart file, and not the Javascript when opened in Dartium, and run the Javascript when opened in Firefox or Chromium?

Should I create two pages, one for Dart and one for Javascript? That means I'd have to edit two files when I want to change anything. Feels wrong to me.

Kind regards, Hendrik Jan

---- EDIT ----
I now realise that it might be important that this application is written in PHP using the Laravel framework.

I found the following solution that works for me. In stead of linking to the generated Javascript file (as I did in my question), I link to dart.js which will load the generated Javascript in case Dart is not supported in the browser, like this:

<script type="application/dart" src="/bones/build/web/quiz/quiz1.dart">
</script>
<script src="/bones/build/web/packages/browser/dart.js">
</script>

This makes it possible for me to see the result of my work in Dartium and also in Firefox and Chromium.

You don't have to do anything, let pub build / pub serve handle how the script tags are included into the entry page.

The problem is that you can't build deployable Dart code. dart2dart is experimental and not yet supported (see Run Dart WebApp on Apache Server for more details on dart2dart ). If you use pub serve a Dart capable browser runs the Dart code and a browser that doesn't support Dart runs the code built to JavaScript.

Dartium is also only for development and therefore there is no browser out there that processes Dart code. As far as I know the Dart team tries to have dart2dart ready when Chrome supports Dart.

But for development using pub serve it's just fine and you don't have to do anything special.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM