Quite simply, the modular-js generator will output AMD modules for each class in your Haxe application. The filename is generated from the parent package of each class.
- Install modular-js with haxelib
haxelib install modular-js`
- Add the generator in your HXML file.
- You must specify all of the classes of all the dynamic entry points in your hxml file. This tells the compiler to consider each class for Dead Code Elimination when outputting the files of the Haxe Standard Library.
- Why would you do this?
There are many good reasons to split your project into modules.
- There is less code to push to the browser when you publish updates.
- Debugging is easier because files are logically separated.
Won't loading multiple files make my website slower?
In short, no. The longer answer is, if your server is configured to use SPDY or HTTPS2 and your target browser audience supports one of them, then the slow-down caused by multiple files is not even worth mentioning. To learn more about techniques of making your website load quickly, watch Jake Archibald's talk here.
- How do I add additional requirements to my modules?
@:jsRequire("moduleName") meta data to indicate how the dependency of that external Library should be represented.
- ES6 Modules
- CommonJS Modules