-1

I noticed something by accident. When I create a simple AngularDart application, it runs just fine in Chrome and Firefox (not just Dartium). I understood that this would take an extra step to compile but LO! it runs, as is, in Firefox and Chrome. What gives?

main.dart

import 'package:angular/angular.dart';
import 'package:angular/application_factory.dart';

void main() {
  applicationFactory().run();
}

index.html

<!DOCTYPE html>
<html ng-app>
<head>
    <title>Hello, World!</title>


</head>
<body>

<h3>Hello {{name}}!</h3>
  Name: <input type="text" ng-model="name">

  <script type="application/dart" src="main.dart"></script>
  <script type="text/javascript" src="packages/browser/dart.js"></script>
</body>
</html>

Chrome running Dart

Firefox running Dart

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
Nathaniel Johnson
  • 4,731
  • 1
  • 42
  • 69

1 Answers1

0

DartEditor runs pub serve in the background which serves files to the browser.
When a browser can't process Dart a JavaScript routine is executed which requests the JavaScript source and pub serve transpiles (compiles) on the fly to JavaScript and serves this generated JavaScript to the browser.

So, yes, you need to compile to browsers which don't have native Dart support.

pub build (when run from the CLI runs in release mode by default) in addition to generating JavaScript from Dart also does tree-shaking to remove unused code and minification to make the result JavaScript smaller.
pub serve doesn't do this.

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567