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?
#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.
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!
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
Related
I found a useful demo in github(https://github.com/maggiewu19/compass-gait-simulator). However, the codes didn't work with the newest pydrake. I ran the codes in google colabĀ and got errors.
Any reply will be appreciated.
I see. This is quite old -- it is using RigidBodyPlant which has been replaced by MultibodyPlant.
Drake has supported quite a long deprecation period on this. You can make most of it work by pulling the old RigidBodyPlant classes from attic, e.g. by changing this
from pydrake.all import (Box,
DiagramBuilder,
FindResourceOrThrow,
Isometry3,
SignalLogger,
Simulator)
from pydrake.attic.all import (FloatingBaseType, RigidBodyTree, RigidBodyPlant, VisualElement)
Unfortunately, I didn't leave as long of a deprecation period on PlanarRigidBodyVisualizer in the underactuated repo. You will have to pull an old version of underactuated to make that work.
FTR -- we are currently working on a way to make the colab setup's durable, by having a peg revision of drake (and underactuated) in the setup script. For now, you could download the old version of the underactuated repo, or just that specific file that was removed after it's deprecation period.
I can't guarantee you won't hit more errors after that. It would be much better to use the updated compass gait examples from class which are all using MultibodyPlant.
I recently stumbled across Dart, and got pretty excited about it because it almost feels like that perfect language I've always been looking for. I work with PHP at my job (Yes, I know, ew gross) as a web developer and was excited to try and build a web app using the language. Figured it couldn't be too hard as that's what Dart was originally made for. Turns out it more difficult than I though, and I can't even get off the ground. I was hoping someone else could help point me in the right direction.
So, I really haven't done any real coding in this project at all. I literally downloaded the Dart SDK, used stagehand to create web-simple project, then I added a bin/server.dart file to the project. The code in that file was pretty much taken straight out of the online documentation for the mojito package:
import 'package:mojito/mojito.dart';
main() {
var app = init();
app.router
..addStaticAssetHandler('/static');
app.start();
}
I added the dependency mojito: "^0.6.6" to the pubspec.yaml file as well of course. That's all I've done though, like I say, I haven't even managed to get off the ground yet.
When I run server.dart I get the following error:
'package:convert/src/percent/encoder.dart': malformed type: line 23 pos 13: cannot resolve class 'ChunkedConverter' from 'PercentEncoder'
I get the exact same error message if I try to build a server with the shelf_rest package instead of the mojito package.
A search of that error message doesn't bring up too much helpful info, though I found one forum where someone recommended adding convert: ^2.0.1 to the dependencies. Apparently there was a change made in that package that causes incompatibility with other packages. I tried that suggestion but it doesn't seem to be resolving the issue.
I'm certain the issue is some sort of dependency issue, I'm probably using a mix of dependencies that I guess just aren't meshing right. If someone could help me figure out what I'm doing wrong it would be much appreciated. I want to learn and start using Dart but obviously I'm not having such great luck with it...
Here's what the pubspec.yaml looks like in case it helps:
environment:
sdk: '>=1.24.0 <2.0.0'
dependencies:
shelf: ^0.6.0
mojito: "^0.6.6"
convert: ^2.0.1
dev_dependencies:
browser: ^0.10.0
dart_to_js_script_rewriter: ^1.0.1
transformers:
- dart_to_js_script_rewriter
The last version of mojito was uploaded in October 2016 and it seems abandoned. Since then, Dart has added Strong mode and begun transitioning to Dart 2. This included significant changes to the type system and updates to SDK libraries.
Additionally, transformers have also been removed - any documentation you find referencing them is out of date. And in this case, the dart2js script rewriter is for client side JavaScript, not servers.
If you're looking for Server libraries, I would recommend just starting with the latest version of Shelf
In a Flutter app, I have a dart file located at FlutterTest\sandbox\lib\my_widget\my_widget.dart, containing a class called MyWidget.
Can I, from this class, get the location of the file where it is defined?
This is not possible. Flutter disable dart:mirror so you can't use reflection.
As mentioned in another answer/comments, that information is stripped out at runtime.
However, if you're motivated enough you could write a pub transformer that uses regex to pick up a special symbol you define and exchange it for the file path at runtime. Edit: transformers aren't supported in flutter.
You may be able to do this with the Build package & tooling introduced in Dart 2, but you'll have to make sure you're using a version of flutter that uses dart 2 (the beta branch/channel probably doesn't yet, the dev may or may not, but master does).
I am curious to know if its possible to have Asynchronous module definition with Angular.dart (or dart in general), if yes, then please share a sample code for such a single page application.
AMD is made largely irrelevant by the fact that Dart comes with a complete module system that is built into the language. That is the purpose of the import statement. Dart files are dynamically loaded in Dartium. If you are using the darttojs transpiler, it will create a single large file. The solution to this is to use use the DeferredLibrary class which will cause darttojs to create separate javascript files for each annotated import
See Seth Ladd's blog post for more details.
Why does the Dart2JS compiler not generate code that includes "use strict" at the top of each of the script files? If all generated Javascript code is valid ECMA5 code, then shouldn't the compiler automatically add the "use strict" command?
Update:
Apparently this is already being tracked by issue 1686.
To formally answer, this feature request can be found in issue 1686 in the Dart issue tracker.
As for why, there hasn't been much demand for it and the dart2js team has been focused on language conformance and performance.