Search code examples
sublimetext3haxe

How to build javascript files from Haxe using Sublime Text


I have installed Haxe for OS X, and I have installed the Haxe code completion package for Sublime Text. So far this is working - I can type Haxe code and Sublime Text will recognize it.

I have read the Haxe tutorials and documentation, but I can't seem to find anything about compiling the Haxe code to javascript from Sublime Text.

I'm sure it has something to do with the 'build system' in Sublime Text, but I don't see how to get Haxe's tutorial commands into Sublime Text?

From the Haxe website:

Input:

-cp path: Adds a class path where .hx source files or packages (sub-directories) can be found.

-lib library_name: Adds a Haxelib library.

-main dot_path: Sets the main class.

Output:

-js file_name: Generates Javascript source code in specified file

-as3 directory: Generates Actionscript 3 source code in specified directory.

An example of a build system from the unofficial SublimeText documentation:

{
    "cmd": ["python", "-u", "$file"],
    "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
    "selector": "source.python"
}

Does anybody have any idea how to use this? The Haxe website seems short on working examples.


Solution

  • Just create a build.hxml file at the root of your project. Put all the compilation settings in there as you described above and use CTRL+ENTER to compile. You can have multiple hxml files if you need to compile to multiple targets or chain several compilation procedures in the same build file. Also the file will be used for autocompletion.