Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which files are generated when executing `dart2js`? and why?

Tags:

dart

dart2js

dart2js probably generates .js.map, .js.deps and .precompiled.js.

What's the purpose of them? and I donno why dart2js doens't remove them after finishing compile.

like image 860
Sungguk Lim Avatar asked Dec 01 '13 17:12

Sungguk Lim


People also ask

What is dart2js?

Contents. Version note: Dart 2.18 removes the dart2js command-line tool from the Dart package, but retains the dart2js compiler. Use dart compile js to compile Dart code to deployable JavaScript.

Does Dart compile to binary?

Not only does Dart compile to JavaScript -- it's done this from day 1 -- but it also compiles to ARM binary via LLVM for iOS applications... meaning that compiling to WASM should be a trivial option to enable bringing near-native computational speeds to any targeted platform.

Can Dart be compiled?

Dart programs can be compiled to native x64 machine code for running in a Terminal/Command Prompt on desktop operating systems such as Windows, macOS, and Linux. For more details, see the dart compile documentation.


2 Answers

All files are generated by dart2js on purpose:

.js: The JavaScript output of your application

.precompiled.js: The JavaScript output but with content security policy (CSP) support

.js.map: source map file used for debugging the JavaScript code in the browser. It contains a mapping from JavaScript to Dart code lines.

.js.deps: contains a list list of all references files used for compilation, prop ably for debugging but I'm not sure about this.

like image 168
Fox32 Avatar answered Sep 29 '22 04:09

Fox32


Here is what I believe is correct at the time I write this:

  • .js - the main JavaScript output of dart2js

    Convention is to us the -o option to set the generated Javascript filename to end with .dart.js to differentiate generated Javascript from explicit Javascript in the Dart project. E.g.:

    dart2js -o main.dart.js main.dart

    pub-build does that by default. The dart.js file assumes this convention is used. Sample Dart .gitignore files often include *.dart.js.

  • .js.map - provides source maps from JavaScript to Dart that make debugging easier

  • .js.deps - what files were used when compiling with dart2js

  • .info.json - json file with information about the generated code (if --dump-info specified)

  • .js_1.part.js, .js_2.part.js etc. - parts of deferred imports

    Sample Dart .gitignore files often include *.js_ to cover these files.

  • The --deferred-map option will generate a json file that you must provide a file name for.

  • .precompiled.js is no longer produced by dart2js

See:

  1. https://www.dartlang.org/tools/private-files.html
  2. https://github.com/dart-lang/www.dartlang.org/issues/1496 for my conversation with the site authors on making some adjustments.
  3. https://www.dartlang.org/tools/dart2js/
  4. https://github.com/github/gitignore/blob/master/Dart.gitignore.
like image 43
Argenti Apparatus Avatar answered Sep 29 '22 04:09

Argenti Apparatus