bclinkinbeard/angular

How to combine with jQuery?

Closed this issue · 3 comments

I'm attempting to use angular using Browserify, but I'm unable to figure out how to get AngularJS to use jQuery in this distribution. In a regular AngularJS build, it would simply replace its internal jQLite with jQuery if jQuery turns out to already be loaded, but that is obviously not possible here due to the isolation that Browserify provides.

How can I make angular use the real jQuery module instead of jQLite?

On further inspection, it appears that this is literally unsupported in this package.

As a workaround, I've removed the angular package, downloaded a 'standard' AngularJS build, and applied the following browserify-shim config in my package.json (irrelevant parts cut out):

  "browser": {
    "angular": "./shimmable/angular.js",
    "jquery": "./node_modules/jquery/dist/jquery.js"
  },
  "browserify": {
    "transform": [
      "browserify-shim"
    ]
  },
  "browserify-shim": {
    "angular": {
      "depends": "jquery",
      "exports": "angular"
    },
    "jquery": {
      "exports": "jQuery"
    }
  }

It would probably be a good idea to update this package to support drop-in usage of jQuery (from npm), as it would support when using a standard build.

Hi there, maybe you can try this before you require angular for the first time:

global.jQuery = require('jquery')

It's a bit hackish but it works for me.

That's what I do too.

global.jQuery = global.$ = require('jquery');