Using Browserify with jQuery Plugins

て烟熏妆下的殇ゞ 提交于 2019-12-19 16:49:13

问题


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 requireing 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.


回答1:


Turns 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.



来源:https://stackoverflow.com/questions/24707406/using-browserify-with-jquery-plugins

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!