How to split js libraries


I’m developing a Lime project with serveral classes and using openfl library but I need to split the final project.js into 2 parts: myclasses.js and openfl.js

How can I do compile it for this purpose?

Thanks :slight_smile:

We have a version of OpenFL designed to work as a standalone JS file.

If you use OpenFL from NPM then it will use this version. It is compatible with plain JavaScript but there also are Haxe externs, too.

We do not currently allow this from Haxelib but it would be possible – in principle the <source path="" /> needs to point to OpenFL’s externs and a <dependency path="" /> needs to point to the compiled “openfl.js” or “openfl.min.js”

What if we supported this using Haxelib? Would it make sense to support it behind a define? What would we call it? (IE: <define name="standalone-js" /><haxelib name="openfl" /> etc)

There’s also a project called “haxe-modular” that works for code splitting that I think can split OpenFL from your project as well

Thanks for answer so soon.

My project.xml contains:

<source path="src"/>
<dependency path="lib/openfl.js"/>
<haxelib name="openfl"/> (Do I delete this line???)

When you tell me it needs to point to OpenFL’s externs… sorry but where are exactly this files? I have finded OpenFL’s hx,js and ts files with extern class declarations into lib directory, but I think it is incomplete… for example there isn’t Application.hx into display directory or the entire _internal directory so it fails when I compile.

Excuse my ignorance… and thanks again.

I suppose the answer is not this easy though I’m still interested in an official solution

I’m still playing with this on my end

I was just working through a similar thing w/ some help from singmajesty. Here is what I did:

Make sure to npm install haxe-modular globally and also include it in your project.xml like this:

<haxelib name="modular" />

Then within your classes, you would have some logic like this:

    Bundle.load(Class).then(function(_) {
        var classLoaded = new Class();

Once all that is there you will want to run:

lime build html5 -debug

Which should generate the classes (you’ll see an emit in the console) and would see the newly created .js files along side the main .js file.