使用Browserify和jQuery插件 [英] Using Browserify with jQuery Plugins

查看:89
本文介绍了使用Browserify和jQuery插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一些简短的背景:我正在使用browserify和browserify-shim(和gulp来构建)来创建一个Web应用程序。在此问题之前,我从npm require ing jquery所以我没有遇到任何问题。一旦我开始进行一些优化,我就意识到包含jQuery的程度有多大。所以现在我从带有脚本标签的CDN抓取jQuery并将其放在bundle.js文件之前。但是我在将jQuery声明为全局并且在browserify和browserify-shim中正确填充我的jQuery插件时遇到了问题。当我运行gulp进行构建时,我不断收到同样的错误:

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:[编译错误]模块jquery找不到/Volumes/Chetan/Users/cshenoy/Projects/urbanstems-node/app/plugins/jquery.inview.js

似乎browserify-shim并没有认识到jQuery是一个全球性的。

It seems like browserify-shim isn't picking up on jQuery being a global.

作为参考,我使用 inview插件

这是我的package.json及相关部分

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.

推荐答案

原来你不需要声明每个jQuery插件 browserify-shim 如果它只依赖于jQuery。我刚刚删除了inview条目,一切正常。

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.

这篇关于使用Browserify和jQuery插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆