No announcement yet.

Outputting a Bridge.NET project for use in NodeJs

  • Filter
  • Time
  • Show
Clear All
new posts

    Outputting a Bridge.NET project for use in NodeJs


    I've been toying around with Bridge.NET to compile a C# application to be usable as a NodeJS application, in particular for the Screeps game. I have seen the previous post on this subject and I've happily used the information for that post. I have seen the Retyped bindings.

    I'm not much of a Javascript / Typescript user. I've used both in the past for both professional and hobby projects but I'm in no way an expert, especially when it comes to my first question:
    I see Bridge.NET outputs my code in JS files inside Bridge.define method calls. Using the [Ready] attribute I can see that I can instruct Bridge to use that particular point as an entrypoint. However, Screeps uses a tick based architecture where different players export their main loop using a
    module.exports.loop = function() { /* code goes here */ }
    I'm cool writing my own main.js file that imports both Bridge and my own code and exports my main loop through that particular format. However, how exact do I instantiate my App class from there? I don't see Bridge.js do a module.exports = ... nor does my own code and this confuses me.

    Thank you,

    Done a bit more reading and the answer is simple: I should've added an
    [assembly: Module(ModuleType.CommonJS, "ScreepsAI")]
    attribute on top of the App class and it'll generate the module.exports at the end of the file.

    I also added a
      "combineScripts": true
    to the bridge.json file and that would combine everything into one. This puts up another problem tho, as the combined JS file is 2.8MB in size, which exceeds the script size limit by 800Kb. Is there a way to trim down the output JS by removing all functionality that isn't used?


      You could always remove the meta data - reflection from bridge.js
      Remove meta data - reflection from your js files.

      you could also gzip all the js and decompile at run time and write the js.