Javascript target, how to bundle everything together in one .js file

Sorry guys, I am quite new to haxe so perhaps I miss something.

I am trying to compile my project to generate a javascript bundle like this:

haxe -lib pixijs -cp core/haxe/src -cp app/haxe/src -main com.company.App -js app/js/bundle.js -D js-source-map

Everything works fine but the output js doesn’t seem to include everything, for example pixi… in order to make it work, I need to include pixi before my bundle.js like this:

     <script src="core/js/pixi.min.js"></script>
     <script src="app/js/bundle.js"></script>

is there a way to make haxe bundle everything together?
Even if I include the whole pixijs haxe into my src directories, it’s not being included in the bundle? why?

You can use haxe.macro.Compiler.includeFile() for this, see also this blog post:

https://blog.onthewings.net/2015/07/22/including-external-js-lib-in-haxe-output/

The reason why you don’t have pixi included is because the lib pixijs is only a set of externs, and not the library itself.

Thanks, that actually worked. Understand now that was only a set of externs.

1 Like

Another option for bundling files is to use Webpack, which makes it easy to load JS files from NPM and include them in your bundle.

I’ve not used pixi js but happy to help you figure it out if you want to.

Here’s the info on the Haxe loader we wrote for Webpack: GitHub - jasononeil/webpack-haxe-loader: Webpack loader for the Haxe programming language.

1 Like