Confusion about npm + haxelib


#1

Hey guys,

A lot seems to have happened since my last visit here ! :+1:

But now I’m a bit confused about it all. Maybe someone can explain this a little bit, or point me to some info ?

Is npm 100% parallel to haxelib, or is it only meant for web targets ?
In the future, will we need 2 separate projects if we want for example the windows target (exe) and a demo we can play in a web browser ?


#2

The NPM version is only meant for web targets.

Web targets will always also be available via Haxe / Haxelib (the NPM version still uses Haxe to compile OpenFL sources to JS). So when it comes to what you can target, the NPM version is strictly inferior.


#3

And is there an obvious reason why one might want to use npm over haxelib (specifically for games) ?


#4

Not from my perspective - I really like Haxe, and as mentioned, you’re really just locking yourself in to a small subset of OpenFL’s possible targets with the NPM version… Some people might prefer JS/TS and the NPM ecosystem over Haxe though? ¯\(ツ)


#5

I also quite like Haxe and OpenFL. But I’m getting a bit worried that all this extra ‘stuff’ might be getting a bit much for one person to maintain …


#6

The NPM release does have a few advantages/differences, but as @Gama11 mentioned, the NPM tooling is not designed for C++/Neko/HashLink, but is strictly JavaScript. You can target desktop or mobile using something like Electron or PhoneGap, but let’s focus primarily on the browser.

NPM releases have a version of OpenFL that is already compiled. This makes OpenFL’s sources external to your project, which makes OpenFL compatible (and available) on a CDN, and is good for multiple embeds. You have a few minor things you can do that aren’t available in the Haxelib releases, such as new Stage()

var stage = new Stage (550, 400);
var sprite = new Sprite ();
sprite.graphics.beginFill (0xFF0000);
sprite.graphics.drawRect (0, 0, 100, 100);
stage.addChild (sprite);

document.body.appendChild (stage.element);

Our default templates for NPM are available for JavaScript (ES6 and ES5), TypeScript, and still for Haxe, there’s even (beta) support for ActionScript 3.0 using Apache Royale.

They also use Webpack, which together with NPM makes integrating external code easier, uses local installs of Haxe, and supports hot-reloading, so npm start -s launches a browser window, recompiles your code automatically when changed, and refreshes the browser window, too. This alone is nice for development.


#7

Thank you for explaining !
Although I can’t say I understood it all :flushed: … To an inexperienced programmer it’s all starting to look a bit like magic.