Sharing common files between modules in HaxeJS

67 views
Skip to first unread message

David Gofman

unread,
Nov 8, 2012, 11:55:02 PM11/8/12
to haxe...@googlegroups.com
Hi guys,
I finally was able to achieve a goal compiling  Haxe projects to different JS files without duplicating the same code in JavaScript files.
I would like to share my experience using FlashDevelop IDE:
 
// Common.hxproj - Project
 
1) Copy and paste existing project into the same directory and rename Common.hxproj
2) Move a "common" folder outside your "src" project directory
3) Replace package names, for example if package name starts "com.compnay.common" I rename to "common.com.company", the main idea we don't want override defined "com" from common.js in our modules
4) Be sure your "common" and "src" in your Source Path
6) Remove "Main Class" (blank) in Project->Properties->Compiler Options
5) Add additional compiler arguments:
 
--macro exclude('com.company')
--macro include('common.com.company')
 
5) Change a file output name bin/common.js
6) Compile and check all common and default haxe libraries compiled into common.js
 
//  Module1.hxproj
 
I would like exclude all files defined in common.js and compile only my project classes
 
1) Update your HTML header declaration by path to common.js
          <script type="text/javascript" src="common.js"></script>
 
2) Add "common" directory to your Source Path
 
3) Update Compiler Arguments:
--macro exclude('common.com.company')
--macro exclude('Std')
--macro exclude('EReg')
--macro exclude('Hash')
--macro exclude('List')
--macro exclude('IntIter')
--macro exclude('Lambda')
--macro exclude('Reflect')
--macro exclude('StringBuf')
--macro exclude('StringTools')
--macro exclude('DateTools')
--macro exclude('HxOverrides')
--macro exclude('ValueType')
--macro exclude('Type')
--macro exclude('Math')
--macro exclude('haxe')
--macro exclude('js')
 
4) Compile project, now your module JS file is clean and easier for read!!!
 
Only one problem when I am executing a project I am gettin the error "com" or "js" packages are undefined.
The reason because in common.js file we are declaring all packages using "var"  what visible inside this file.
For now I manually mapping "var" to "window" in the end of my common.js. I hope someone can suggest a better way
 
window.common = common;
window.org = org;
window.Std = Std;
window.EReg = EReg;
window.Hash = Hash;
window.List = List;
window.IntIter = IntIter;
window.Lambda = Lambda;
window.Reflect = Reflect;
window.StringBuf = StringBuf;
window.StringTools = StringTools;
window.DateTools = DateTools;
window.HxOverrides = HxOverrides;
window.ValueType = ValueType;
window.Type = Type;
window.Math = Math;
window.haxe = haxe;
window.js = js;
 
 
 
Thanks,
David
 
 
 
Reply all
Reply to author
Forward
0 new messages