admin管理员组文章数量:1316515
Some brief background: I'm using browserify and browserify-shim (and gulp to build) to create a web app. Prior to this issue, I was require
ing jquery from npm so I had no issues. Once I started doing some optimization, I realized how massive the bundle was with jQuery included. So now I'm grabbing jQuery from a CDN with the script tag and placing it before the bundle.js file. But I'm having issues declaring jQuery as a global and properly shimming my jQuery plugins in browserify and browserify-shim. When I run gulp to build, I keep getting the same error:
[gulp] gulp-notify: [Compile Error] module "jquery" not found from "/Volumes/Chetan/Users/cshenoy/Projects/urbanstems-node/app/plugins/jquery.inview.js"
It seems like browserify-shim isn't picking up on jQuery being a global.
For reference, I'm using the inview plugin.
Here's my package.json with the relevant parts
"browser": {
"inview": "./app/plugins/jquery.inview.js"
},
"browserify-shim": {
"jquery": "global:jQuery",
"inview": {
"depends": [
"jquery"
]
}
}
Let me know what else I can include to help diagnose the error.
Some brief background: I'm using browserify and browserify-shim (and gulp to build) to create a web app. Prior to this issue, I was require
ing jquery from npm so I had no issues. Once I started doing some optimization, I realized how massive the bundle was with jQuery included. So now I'm grabbing jQuery from a CDN with the script tag and placing it before the bundle.js file. But I'm having issues declaring jQuery as a global and properly shimming my jQuery plugins in browserify and browserify-shim. When I run gulp to build, I keep getting the same error:
[gulp] gulp-notify: [Compile Error] module "jquery" not found from "/Volumes/Chetan/Users/cshenoy/Projects/urbanstems-node/app/plugins/jquery.inview.js"
It seems like browserify-shim isn't picking up on jQuery being a global.
For reference, I'm using the inview plugin.
Here's my package.json with the relevant parts
"browser": {
"inview": "./app/plugins/jquery.inview.js"
},
"browserify-shim": {
"jquery": "global:jQuery",
"inview": {
"depends": [
"jquery"
]
}
}
Let me know what else I can include to help diagnose the error.
Share Improve this question edited Jul 14, 2014 at 16:42 Chetan Shenoy asked Jul 11, 2014 at 22:14 Chetan ShenoyChetan Shenoy 8431 gold badge10 silver badges19 bronze badges 2-
4
I'm curious about going the opposite direction. When you
require('jquery')
from npm, how were you able to expose it globally so plugins still worked? – Michael Martin-Smucker Commented Aug 13, 2014 at 21:37 - I didn't expose it globally when I installed it from npm. The value for jquery inside browserify-shim would be $ or jQuery. Then all your jQuery-dependent plugins would be listed below it with the depends field listing jquery. – Chetan Shenoy Commented Aug 14, 2014 at 18:23
1 Answer
Reset to default 6Turns out you don't need to declare every jQuery plugin under browserify-shim
if it only depends on jQuery. I just deleted the inview entry and everything works fine.
本文标签: javascriptUsing Browserify with jQuery PluginsStack Overflow
版权声明:本文标题:javascript - Using Browserify with jQuery Plugins - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742007528a2412263.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论