Search code examples
javascripthaxehaxelib

How to compile Haxe into JavaScript?


Grunt-Haxe has been built around 3 years ago. Installing it along with NPM haxelib, did provide a way to compile pure JavaScript with one issue of not being able utilize JqueryExtern library; it simply throws an error each time when trying to use jQuery class saying it can't be found, even if adding import jQuery.*. It compiles *.Hx files fine with Haxetoolkit but same does not work with haxe-NPM, haxelib, grunt-haxe it just ignores the JqueryExtern library when compiling.

Here is my grunt configuration - do I have something there that is causing these failures? The haxe version I use is Haxe 3.2.1., I can't run gulp watch as it would require a task assigned for Haxe but that does not exist yet

   haxe: {
        complete_example: {
            main     : 'Main',
            classpath: [ app.src.hx],
            libs     : ['jQueryExtern' ], /*specify haxelib libraries */
            //flags    : [ 'something', 'createjs' ], /* define conditional compilation flags */
            //macros   : [ 'Mymacro.doSomethingCool()' ], /*call the given macro*/
            //resources: [ 'activity/xml/map-layout.json@map_layout' ], /*define named resource files*/
            //misc     : [ '-debug', "--dead-code-elimination", "--js-modern" ], /* add any other arguments*/
            output   : app.dest.js + 'hx.js',
            onError  : function ( e ) {
                /*custom error message */
                console.log( 'There was a problem...\n' + e );
            },
            force    : true /*continue processing task (like --force)*/
        }
    }
grunt.loadNpmTasks( 'grunt-haxe' );

Solution

  • The only way I was able to compile it is by using file watchers plugin for intelliJ IDEA browser along with official version of haxe toolkit. No other plugins were found to do this job.