大佬教程收集整理的这篇文章主要介绍了将Haxe模块导入node.js脚本,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
function requireHaxe(variableTorequire,haxeFileLOCATIOn){ //generate a JavaScript module from the Haxe file,and then return the generated JavaScript module }
//Haxenode.hx class Haxenode { @:expose("Hello") public static function Hello(){ return "Hello"; } }
@:expose(“Hello”)部分是在module.exports中放置一些东西.
现在推出
haxe -js haxenode.js -dce no Haxenode
现在您可以在Nodejs中使用haxenode.js
var haxenode = require('./haxenode.js'); var Hello = haxenode.Hello;
所以,这个结合在一起就是你问题的答案:
var cp = require('child_process'); function requireHaxe(haxeClassPath,cb){ //generate a JavaScript module from the Haxe file,and then return the generated JavaScript module cp.exec('haxe -js haxenode.js -dce no ' + haxeClassPath,function(err){ if (err){ cb(err); return; } cb(null,require('./haxenode.js')); }); }
但是不要这样做 – 最好将haxe编译为构建步骤(使用所有必需的编译选项),然后在运行时使用常规require.
以上是大佬教程为你收集整理的将Haxe模块导入node.js脚本全部内容,希望文章能够帮你解决将Haxe模块导入node.js脚本所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。