"找不到模块'jQuery的'" - 处理中browserify jQuery的全局和AngularJS与咕嘟咕嘟 [英] "Cannot find module 'jquery'" - handling globals for JQuery and AngularJS in browserify with Gulp

查看:311
本文介绍了"找不到模块'jQuery的'" - 处理中browserify jQuery的全局和AngularJS与咕嘟咕嘟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在试图建立一个项目,利用 AngularJS Browserify 咕嘟咕嘟一个优秀的开发者体验,一种产生分配模块(角中的说法)。这个想法是有一个自我记录的项目,如角引导,也产生在另一个应用程序中使用的耗材配送。

I've been trying to create a project that utilizes AngularJS, Browserify and Gulp for an excellent developer experience, one that produces a distributable 'module' (in Angular parlance). The idea being to have a self-documented project, like Angular Bootstrap, that also produces a consumable distribution for use in another application.

我们已经与咕嘟咕嘟有很大的成绩,但我们遇到与 browserify / browserify-垫片麻烦 。此外,不幸的是,大多数的例子在那里要么不使用一饮而尽,或使用吞掉-browserify ,这已被列入黑名单/结束。

We've had great results with Gulp, but we're having trouble with browserify/browserify-shim. Also, unfortunately, most of the examples out there either don't use gulp, or use gulp-browserify, which has been blacklisted/ended.

我们正在包括 AngularJS JQuery的谷歌CDN <脚本> 标签并宣布角:全球:角jQuery的:全球:$在我们的 browserify-垫片配置的package.json ,但我们正在找不到模块当我们试图用户 VAR角=要求('角')变量$ =要求('jQuery的')里面我们browserified- code的(一旦它在浏览器中运行)。

We're including AngularJS and JQuery from Google CDN as <script> tags and have declared "angular" : "global:angular" and "jquery" : "global:$" in our browserify-shim config in package.json, but we're getting "cannot find module" when we try to user var angular = require('angular') and var $ = require('jquery') inside of our browserified-code (once it runs in the browser).

我已经创建了接近最低提炼下来的示例项目。

I've created a sample project that distills this down close to the minimum.

的code的样本库,请

在克隆的,你可以运行故宫安装,那么'亭子安装,那么'吞掉'多browserify根文件夹中生成的文件并运行测试服务器。

Once cloned, you would run 'npm install', then 'bower install', then 'gulp' from the root of the multi-browserify folder to generate the files and run the test server.

通过一饮而尽运行,您可以在HTTP访问现场HTML://:4000 / gulp.html

With gulp running, you can access the live HTML at http://:4000/gulp.html

任何帮助将大大AP preciated - 我想知道,如果我们遇到一个bug /问题与一饮而尽,browserify,乙烯基源流等,或者相交的可能性较大,我们只是不太明白呢。

Any help would be greatly appreciated - I'm wondering if we've come across a bug/issue with the intersection of gulp, browserify, vinyl-source-stream, etc, or more likely, we just don't quite get it yet.

推荐答案

从CDN的要求取回你的依赖?如果没有,你可以使用NPM为你的依赖,让browserify他们的魔法为你。

Is retrieving your dependencies from a CDN a requirement? If not, you could use npm for your dependencies and let browserify magic them up for you.

jQuery和角度都可以通过NPM可用,因此使用jQuery作为一个例子,你可以只声明它的的package.json ,就像这样:

JQuery and Angular are available via npm, so using jquery as an example you could just declare it in your package.json, like so:

  ...
  "dependencies": {
    "jquery": "^1.11.1"
  },
  ...

另外,运行 NPM安装&LT;包装及GT; -s 从包含的package.json 将安装指定的模块并将其保存为一个依赖于你的包目录以.json 文件。

Alternatively, running npm install <package> -s from the directory containing your package.json will install the specified module and save it as a dependency in your package.json file.

一旦安装这种依赖关系(以及任何你想要的其他人),你可以继续在app.js使用它们如下:

Once you have installed this dependency (and any others you desire), you can go ahead and use them in your app.js as follows:

var $ = require('jquery');

$('<div>Hello World, I\'m using JQuery!</div>').appendTo('body');

这么简单,没必要使用凉亭或browserify-垫片 - browserify将翻检node_modules文件夹,找到他们。我还没有尝试过的角度这(我不得不尝试安装它的问题) - 但它是可以通过 NPM ,所以它应该工作。

这篇关于&QUOT;找不到模块'jQuery的'&QUOT; - 处理中browserify jQuery的全局和AngularJS与咕嘟咕嘟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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