Announcement

Collapse
No announcement yet.

[CLOSED] [#258] Support for AMD and CommonJS Modules

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

    [CLOSED] [#258] Support for AMD and CommonJS Modules

    It would be great if Bridge.NET could also support AMD and CommonJS modules. I'm considering Bridge.NET for a NodeJS project so having the ability to support CommonJS would be a sure win. :)

    Thanks!
    Last edited by Leonid; 2015-05-22 @ 09:48 AM.

    #2
    Hello sombralobo ! Thanks for starting this discussion.

    Yes, we are working on RequireJS support.

    The feature request is being tracked in the following GitHub issue:

    https://github.com/bridgedotnet/Bridge/issues/258

    We will update the community when it's available.

    Comment


      #3
      As for Bridge 1.7.0 you can try with `Module` and `ModuleDependency` attributes. If a dependency might be determined automatically, for example, if you use a class from some module in another module, a dependency will be added automatically.

      For example, these two C# files:

      Module1.cs
      using Bridge;
      
      namespace Module1
      {
          [Module("Module1")]
          public class SomeEntity
          {
          }
      }
      Module2.cs
      using Bridge;
      
      namespace Module2
      {
          [Module("Module2")]
          // [ModuleDependency("SomeModule")] // Please use for module dependencies that cannot be determined automatically
          public class App
          {
              public static void Main()
              {
                  var test = new Module1.SomeEntity();
              }
          }
      }
      produces these JavaScript files

      module1.js
      define("Module1", ["bridge"], function (_) {
          var exports = { };
          Bridge.define('Module1.SomeEntity', {
              $scope: exports
          });    
          return exports;
      });
      module2.js
      define("Module2", ["bridge","Module1"], function (_, Module1) {
          var exports = { };
          Bridge.define('Module2.App', {
              $scope: exports,
              statics: {
                  main: function () {
                      var test = new Module1.Module1.SomeEntity();
                  }
              }
          });    
          return exports;
      });
      Your feedback is very much appreciated.

      Comment


        #4
        Created an individual issue for CommonJS support:
        https://github.com/bridgedotnet/Bridge/issues/813

        Comment


          #5
          I'm playing with the module support and I saw that it does not support path based modules. For example, when using [Module("path/to/my/module")].

          This is important if you want to generate path related modules, like for simulating dynamic loading with frameworks like aurelia and angular 2 or even to work with some route libraries.
          Last edited by geoffrey.mcgill; 2018-05-07 @ 07:08 AM.

          Comment


            #6
            AMD and CommonJS Modules have been supported for a while now.

            https://github.com/bridgedotnet/Brid...dule-attribute

            Hope this helps.

            Comment


              #7
              I'm playing with the module support and I saw that it does not support path based modules.
              Path based modules are also supported, you can use ExportAsNamespace property to configure an alias for the module variable.

              https://deck.net/cbdd2930d35e318afa8cf99ae4fa6aa1

              Comment


                #8
                Andrey, path based modules don't work. The example you posted was using an external module. But if you define a path based module, it won't work:

                https://deck.net/f79ea85da35398219d73a94b23d20002

                Best regards

                Comment


                  #9
                  Hi emumanu,

                  Thanks for pointing to the defect with non-external modules. I think it's related to Issue #3549.
                  I'll add a comment about that case into the description.

                  Comment

                  Working...
                  X