In my application I generate big dart classes. Right now I compile them on the server, which takes CPU time. It would be much better to compile the Dart code within the browser. The code is then loaded via spawnURI.
Is it possible to invoke the dart2js compiler from within Dart code in a supported way as it is done in try.dartlang.org or do I need to copy the compiler into my project?
Use the dart compile command to compile a Dart program to a target platform. The output—which you specify using a subcommand—can either include a Dart runtime or be a module (also known as a snapshot). For more information about this and other dart commands, see the Dart command-line tool page.
Dart supports the web as one of its core platforms. Dart-to-JavaScript compilers are available both for development (with a quick edit-refresh cycle) and for production (with a focus on code size and speed).
To run a Dart console application: Install the Code Runner Extension. Open the Dart code file in Text Editor, then use shortcut Ctrl+Alt+N , or right click the Text Editor and then click Run Code in context menu, the Dart console application will run and the output will be shown in the Output Window.
Compiling Dart to JavaScript will be faster on the server, because you can run dart2js via Dart VM. try.dartlang.org is running in a special version of dart2js, which has not been merged into the main source code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With