OpenFL separate module?

As currently I am compiling openFL project to js, I have both openfl, lime and my source code into one file.
How would I compile my source code into a separate js file? what’s the command line?

Also, is there a pre-compiled openfl module for latest release to download and use? Do I need to use lime separate module too?

There is a -Dmodular define, which should break up our HTML5 output into additional files. However, we are also working on a NPM-based version of OpenFL, which supports either distinct CommonJS modules, or also generates a single “openfl.js” distribution file that can be used. Work on this is continuing, you can read more here: http://www.npmjs.com/package/openfl

Technically, would it be possible to get only the dependencies that my project needs in order to run? thus, avoiding those framework parts that my project does not use, and thus, saving more bytes?

Also, is there an example project which is compiled with -Dmodular? as I tried to do so, but I’ve noticed that the look of components got different, ex:

44 AM

I’ve loaded the following before my project module:

    %script{:src => "#{lab_info.url}lib/pako.min.js"}
    %script{:src => "#{lab_info.url}lib/FileSaver.min.js"}
    %script{:src => "#{lab_info.url}lib/howler.min.js"}
    %script{:src => "#{lab_info.url}lib/haxe.js"}
    %script{:src => "#{lab_info.url}lib/lime.js"}
    %script{:src => "#{lab_info.url}lib/openfl.js"}

The NPM approach does use only the parts that you use, but doesn’t have Lime tool support. The -Dmodular approach should separate into different files (and shouldn’t change the behavior as far as I know) but doesn’t know what features you used, so it includes all features

Hello, if your goal is to load parts of your application on-demand, you may want to look into the, confusingly similarly named, Haxe Modular project.

I just registered to the new forum so I’m not sure I can share the URL :wink: it’s “haxe-modular” on Github, under my account “elsassph”. A fix in OpenFl was recently merged to better support this JS code splitting approach - maybe @singmajesty can confirm whether it was released.

There is a conflict between OpenFL’s modular option and haxe-modular’s haxelib version which is also named modular :

When you define a library in your project.xml with the name modular by using this syntax : <haxelib name="modular" />, the resulting .hxml will include a -D modular=0.8.0 line. This will then trigger openfl’s -D modular, which is something you don’t want.

To solve this, you have to download haxe-modular into some directory, and then install it with haxelib dev haxe-modular path/to/modular. Then you can include the library in your project.xml with <haxelib name="haxe-modular" />

PS : The link to haxe-modular is https://github.com/elsassph/haxe-modular/

I tried this but get: $ openfl test html5 -Dcanvas
sh: haxe-split: command not found

in project.xml:
<haxelib name="haxe-modular" />

haxelib list
haxe-modular: [dev:/Users/blah/Documents/devel/haxe/src/haxe-modular]

Try looking at these instructions, it looks like the haxelib name should be “modular” though

Thanks. After doing the npm install, I don’t get the “haxe-split” error and it seems to be doing something, but the output looks the same (no splitting). Here is the output:
$ openfl test html5 -Dcanvas -final
WARNING: Unexpected WhileStatement, at character 1332854
WARNING: Unexpected WhileStatement, at character 1333076
WARNING: Unexpected WhileStatement, at character 1333200
Parsed in: 436ms
Stats: 401 types, 4307 references
AST processed in: 158ms
Bundling…
Graph processed in: 6ms
Emit /Users/blah/Documents/devel/haxe/projects/wechat/Export/html5/bin/GemMiner.js
Write /Users/blah/Documents/devel/haxe/projects/wechat/Export/html5/bin/GemMiner.js
Total process: 647ms

If I understand the library, that’s working. Now you use wrap code that should be split in Bundle.load (if I remember the API correctly) and the haxe-split tool will figure out what code can be split into what files

haxe-modular splits code upon request, but does not specifically separate OpenFL into a separate module. We do do that for our NPM releases, though

I think you have an out-of-date lime version.

Does your lime version have this commit included? https://github.com/openfl/lime/commit/d98c3f2ed13d81ed2b4c38473a69cb9334de8795

Should be included in lime 6.x.x

Thanks. At the command line:
$ lime -v
Lime Command-Line Tools (6.2.0)

but i do have an older version that could be interfering:
$ haxelib list | grep lime
lime-samples: 2.6.0 [6.2.0]
lime: 2.7.0 [6.2.0]

but i do have an older version that could be interfering:

The older version isn’t active, so that shouldn’t be an issue. You can tell by the [] surrounding 6.2.0.

As pointed out:

  • splitting is “on demand”, so read the documentation to create your split points,
  • OpenFl has/had a few incompatibilities in the generated code which hopefully are fixed in very recent releases; the “Unexpected WhileStatement” is an indication of that.

While I believe Lime has been fixed, OpenFl has still incompatible code (VectorData.__init__), and essentially the Stage3D API depends on it. So you can’t split a project using Starling for instance yet.

@elsassph I know that Vector.hx is a bit complex, especially with the defines. The __init__ is actually only when building for NPM builds of OpenFL, so that shouldn’t conflict with haxe-modular :slight_smile:

Aha, indeed VectorData don’t seem to be used for the regular JS target… \o/

@singmajesty it looks like the CanvasGraphics.__init__ fix hasn’t been released yet:

Develop is ok:

Master is not: