Haxe – Compiler flags for JavaScript

Now it’s time to talk about the hxml file in your projects. When you start the compiling process this file be passed to the compiler.

A diagramm of the Haxe compiling process

These compiler flags are required to run the compiling process:

-js

Set’s the location of the out coming JavaScript file.

-main

Tell’s the compiler witch class is the main class of your project.

-cp

These flag will tell the compiler where are your Haxe classes located. You can use additional -cp’s to include another src folders of existing projects like so:
“-cp C:/Users/…/AnotherHaxeProject/src”

These are the optional flags:

-debug

Will output an additionally map file so the browser will tell, e.g. in witch hx class and line number an error occurred.

-js-classic

If you don’t use this flag the out coming JavaScript code will be wrapped in an anonymous function. So the code will be encapsulated. If you use this flag you will be able to access the main class from outside. You can test this in the console of your browser.

-js-flatten

This will flatten you out coming JavaScript code to speed up the perforamce. But you will loose the the namespacing. Output will be access able de_wieland_app_MainApp. This may breaks a few external classes because some of them requires the dot noation.

-js-unflatten

This is the opposite of the flatten flag. It will keep the dot notaion in the out coming JavaScript code. Output will be access able by de.wieland.app.MainApp.

–no-traces

This flag will keep out any traces in the coming JavaScript code. You don’t have to comment out your traces in your Haxe classes. With this flag the compiler will take care of it.

There are many more flag, but these are the most important for compiling to JavaScript.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>