Difference between “Q” and “q” in angularjs and requirejs

后端 未结 2 544
逝去的感伤
逝去的感伤 2021-01-22 11:19

I am creating a single page app built on AngularJS, Breeze, and RequireJS. In setting up AMD with requirejs to work with Angular and Breeze, I encountered an issue with Breeze\'

2条回答
  •  悲哀的现实
    2021-01-22 12:15

    While it is possible to load all modules through requireJs, since my first answer I've discovered a couple of difficulties that made it too troublesome for me.

    If your are going to use requireJs optomize (rjs) and almond to deliver a combined js file with almond's cutdown AMD loader, then you will find errors with some libraries. Specifically I encountered problems with Breeze, & Toastr.

    The optomizer expects explicit define statements with the dependencies explicitly named. Breeze uses variable dependency names as it loads them as it finds it needs them - as its dependencies are configured at runtime.

    The other problem is using CDN files. Almond does not handle any network files, so they must be preloaded. jQuery is the prime CDN candidate, but it is a requirement for many modules including breeze. And optomize shim's can not depend on any CDN file.

    My Solution

    I fixed Toastr for optomize with my own patch https://github.com/CodeSeven/toastr/issues/135.

    But since it was going to be cumbersome to fix Breeze I went back to preloading it via bundling. I also added any libraries I thought would benefit from from being sourced from a CDN.

    I loaded breeze (and its prerequisites) and CDN files via ASP.Net bundles Then define them for requireJs prior to requirejs.config in my main.js

    To use these predefined preloads in my production code, I configure my weyland-config.js with optomize's empty e.g.

                    'jquery':               'empty:',
                    'knockout':             'empty:',
                    'Q':                    'empty:',
                    'breeze':               'empty:',
    

    HTH

提交回复
热议问题