7

I have this code:

// main.dart
import "package:angular/angular.dart";
main () => ngBootstrap();

I make dart2js --minify --out=main.dart.js main.dart

Then i have main.dart.js with size 2.6 MiB (2,744,320 bytes). It is not normal. What i'm doing wrong?

Is angular.dart usable for production at this stage?

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
media-slave24
  • 256
  • 2
  • 7

3 Answers3

5

@media-slave24

Maybe this will be helpful for You: https://code.google.com/p/dart/issues/detail?id=14686

It's reported on dart bug tracking system. Some people using mirrors got 760kb. So it's definitely a bug.

galuszkak
  • 513
  • 4
  • 25
  • Thanks, it works for me, i declared `@MirrorsUsed` and now main.dart.js is _670.6 KiB (686,736 bytes)_. But HOW it works? Official documentation says nothing useful for this. – media-slave24 Nov 22 '13 at 10:28
  • 1
    @media-slave24 https://api.dartlang.org/docs/channels/stable/latest/dart_mirrors/MirrorsUsed.html and https://api.dartlang.org/docs/channels/stable/latest/dart_mirrors.html It's not stable API so it can be changed in future. I hope it will be helpful. – galuszkak Nov 23 '13 at 22:30
  • @media-slave24 670KiB is **17** times bigger than angular.min.js. Are you really considering embedding 670KB of javascript in a webpage? I do not understand why they do not mention anything about this problem on angulardart.org. (By the way, [https://angulardart.org/demo/] loads 2MB of javascript...). – Matthieu G May 01 '14 at 14:08
5

UPDATE (Jan '14): AngularDart 0.9.5 now includes a standard MirrorsUsed list. To finalize it and trigger Dart's tree-shaking optimizations, you need to add a MirrorsUsed to your program

  • listing all the classes you introduce.
  • override: '*' to finalize the MirrorsUsed.

Since helloworld has no new classes, say:

@MirrorsUsed(override: '*')
import 'dart:mirrors';

See Github for the complete helloworld program

The key is to include a @MirrorsUsed annotation in your Dart file. Pavel's link to the AngularDart tutorial is an excellent resource.

To actually answer your question: Yes, AngularDart can be used in production but be aware that it is in "beta" release right now. We expect many breaking API changes!

James deBoer
  • 2,477
  • 15
  • 17
4

Take a look at angular.dart.tutorial Chapter 7 about deployment. It has a section on managing compiled code size:

https://github.com/angular/angular.dart.tutorial/tree/master/Chapter_07

pavelgj
  • 2,246
  • 11
  • 13