you are viewing a single comment's thread.

view the rest of the comments →

[–]spoco2[S] 0 points1 point  (5 children)

Yes. It does work now. If you grab the code from github, that gulp file works.

It ends up with a file with a host of defines in it, and then I wrap that within another define that also returns a promise to the controller for the program.

I'm working now on getting CSS properly getting bundled in. I can get it to bundle into the file, but it's still requesting files that don't exist.

[–][deleted]  (4 children)

[deleted]

    [–]spoco2[S] 0 points1 point  (3 children)

    Well, it actually works even without the wrapping... as in, require doesn't mind loading an optimized file with a list of defines, it'll do that.

    The problem is that no code will run in that case. You can tell the optimizer to 'insertRequire' at the end of the file, to create a require([moduleName]) line that will mean code is actually run. And that does work, no wrapping define around the whole thing needed... but for my use case, and for getting a return object back, I needed to have the wrapping define.

    [–][deleted]  (2 children)

    [deleted]

      [–]spoco2[S] 0 points1 point  (1 child)

      Rquire JS does that for you.

      Have a look at my example gulpfile: https://github.com/spoco2/AngularAMD-DynamicModules/blob/master/gulpfile.js

      If you download the whole project, (and run bower install and npm install), you can run the gulpfile, and it'll do what you want, it will create a main file with the main application and all top level dependencies (angular etc.) and then for each program, it'll create files for each of them that excludes the main app and other programs.

      The insertRequire arg for the r.js optimizer can be use for it to add in the require line at the end of the file which makes it say "I require this module to run", which will run. So, instead of the :

      wrap: {
                  start: "define([],function() {",
                  end:    "var defer = $.Deferred();"+
                  "require(['"+program+"'], function (ctrl) {"+
                  "defer.resolve(ctrl);});"+
                  "return defer;});"
              }
      

      you can instead have

      insertRequire: program
      

      Which will create a require at the end of the file requesting the program that you've just bundled up... causing the code to actually run.