Cognizant-CDE-Australia / generator-confit

Build-tool generator for current and future web.
https://odecee.github.io/generator-confit
Other
29 stars 3 forks source link

Angular cannot pickup jQuery #70

Closed motevallian closed 8 years ago

motevallian commented 8 years ago

I am using Angular 1.5 with jQuery 2.2.4 but Angular cannot pick up jQuery and replace its jqLite with it. Part of the problem is due to the fact that newest versions of jQuery check if they are loaded in a CommonJS syntax (which is the case with Webpack). If so, it does not expose itself as a global property of window object. I tried several approaches including exposing jQuery via expose-loader, importing it and manually setting window.jQuery, etc. but they all fail with Confit. I spotted that the problem is Angular is kind of loaded before all these get a chance to do what I meant. I inspected webpack.config.js and it seems like the problem is due to config.entry.vendor where angular is defined as an entry point library which will be loaded before my application entry point (I guess). I removed those entries and the application works fine in dev mode. I have not had a chance to test it with prod scripts yet. But I am wondering if Confit has a better non-hacky solution for this problem.

uglow commented 8 years ago

Hi Ali,

In confit.json, try modifying the buildJS.frameworkScripts array to include jquery as the first item.

You may also be able to use the DefinePlugin to assign the 'jquery' variable to the jquery module, which should help Angular find it.

Regarding adding LESS support, that is relatively easy, as the code is already supporting other compilers. So go ahead and fork, create a PR with the changes (do a search for "stylus" to see all of the files to change), and I'll add it in. It would take you less than an hour to get this working, in all seriousness.

Have a good weekend! Brett

Sent from my iPhone

On 5 Aug 2016, at 12:27 PM, Ali Motevallian notifications@github.com<mailto:notifications@github.com> wrote:

I am using Angular 1.5 with jQuery 2.2.4 but Angular cannot pick up jQuery and replace its jqLite with it. Part of the problem is due to the fact that newest versions of jQuery check if they are loaded in a CommonJS syntax (which is the case with Webpack). If so, it does not expose itself as a global property of window object. I tried several approaches including exposing jQuery via expose-loader, importing it and manually setting window.jQuery, etc. but they all fail with Confit. I spotted that the problem is Angular is kind of loaded before all these get a chance to do what I meant. I inspected webpack.config.js and it seems like the problem is due to config.entry.vendor where angular is defined as an entry point library which will be loaded before my application entry point (I guess). I removed those entries and the application works fine in dev mode. I have not had a chance to test it with prod scripts yet. But I am wondering if Confit has a better non-hacky solution for this problem.

You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://github.com/odecee/generator-confit/issues/70, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ADzirfL1jf8TEe9fPaYF3xTSI6zjM0seks5qcp-JgaJpZM4JdTMe.