1

Is there any way to compile my dart console project to executable file? Or maybe there are some utilities like launch4j for Java?

Denis Sablukov
  • 3,360
  • 2
  • 26
  • 31

4 Answers4

4

We don't really have all of the pieces together for that – yet.

I'd take a look through this issue: https://github.com/dart-lang/sdk/issues/34343

I'll find the right person on the team to reply here with more details.

Kevin Moore
  • 5,921
  • 2
  • 29
  • 43
1

We can build Dart project to a native app via dart2native.

For example we have main.dart:

import 'package:ansicolor/ansicolor.dart';

main(List<String> arguments) {
  AnsiPen greenPen = AnsiPen()..green();
  AnsiPen greenBackGroundPen = AnsiPen()..green(bg: true);

  AnsiPen redTextBlueBackgroundPen = AnsiPen()..blue(bg: true)..red();

  AnsiPen boldPen = AnsiPen()..white(bold: true);

  AnsiPen someColorPen = AnsiPen()..rgb(r: .5, g: .2, b: .4);

  print(greenPen("Hulk") + " " + greenBackGroundPen("SMASH!!!"));
  print(redTextBlueBackgroundPen("Spider-Man!!!") + " " + boldPen("Far From Home!!!"));

  print(someColorPen("Chameleon"));

  print('\x1B[94m' + "hahAHaHA!!!" + '\x1B[0m');
}

And pubspec.yaml as

name: colored_text_test
description: A sample command-line application.

environment:
  sdk: '>=2.1.0 <3.0.0'

dependencies:
  ansicolor: ^1.0.2

dev_dependencies:
  test: ^1.0.0

We can use command dart2native.bat bin\main.dart and get main.exe as executable output.

Also we can specify name by using -o option: dart2native main.dart -o my_app

Denis Sablukov
  • 3,360
  • 2
  • 26
  • 31
0

Yes, this capability was added in Dart 2.6.

In newer Dart versions, the dart2native tool was integrated into the dart binary. See the tutorial Write command-line apps on dart.dev for details.

Jens Bannmann
  • 4,845
  • 5
  • 49
  • 76
0

Use dart compile for this.

dart compile exe path/to/main/script.dart