Use AMD loading with fallback to global vars#59
Use AMD loading with fallback to global vars#59kennknowles wants to merge 1 commit intocarhartl:masterfrom
Conversation
|
Might want to add |
|
Require.js shim config is your friend. Here's an example from one of my projects: shim: {
'backbone': {
deps: ['underscore', 'jquery'],
exports: 'Backbone'
},
'bootstrap': ['jquery'],
'lib/jquery.cookie': ['jquery'],
'lib/jquery.color': ['jquery']
} |
|
Indeed, I am using a shim now. This patch would remove the need for a shim. |
|
I'll add my voice to the usefulness of this addition. Being AMD compatible would allow me to load it from cdnjs.com instead of having to compile it in. |
|
Thanks for the PR! Will add soon. |
|
@brandonaaron Out of interest, what is the effect of the additional check? |
|
Excellent! |
|
It appears that this commit added support for requirejs, but it created issues with requirejs build. When running requirejs build, I get a jquery.cookie is undefined error at runtime. |
|
Now that it is registering as an AMD module you likely need to add it as a dependency to your other scripts where it is used, if you are using RequireJS. |
|
That's what I am doing. The module is in fact the requirejs build code so the dependency is working, but it is having issue instantiating it. This is only when you do a compile/optimization. It works fine outside of that. |
|
Are you loading it from a CDN? If so, and if it works when not compiled, then it might be a problem with the way r.js compiled external library dependencies. It has broken several times recently. Also if you are using almond.js to compile, then you cannot load it as an external dependency. |
|
Nope. It's local. This is the only plugin having issues. I am using a lot of other jquery plugins as well with no issue. |
|
I wish I could be of more help then. I may attempt to use this plugin again soon, but am not currently. |
|
I have come up against this problem, r.js is compiling the code incorrectly: My shim: And the source currently shows But when it is run through r.js, it becomes: |
|
@chas-ryder I've created #306 as I've come across this issue as well. |
Hello,
I'm porting a project to use RequireJS so I added AMD support to this jquery plugin that I've been using. The change is unobtrusive and backwards compatible, so I hope you'll consider bringing it into the mainline.
I got the basic pattern from here: https://github.com/umdjs/umd/blob/master/jqueryPlugin.js