问题描述
下面是我想要做的: 创建一个包含以下特性的节点包: 在Angular应用程序中安装此节点包(在此称为my-gulp)通过
gulpfile.js
package.json
依赖关系将其作为myApp。)
gulpfile .js
被复制到应用程序根目录中。
我们目前有类似Grunt的设置(尽管没有 Gruntfile.js
复制内容)。对于我们的每个应用程序都有一个共同的设置,而且还有几个定制的Bower组件,它工作得非常好。
到目前为止,我遇到的主要问题是当我将my-gulp添加到myApp的依赖关系时,运行安装,my-gulp进来,但单独的插件(my-gulp依赖)没有看到。他们已安装,但运行像 gulp default
或其他任何显示他们缺少的东西。
我试过
在依赖关系下设置了gulp依赖p>有没有人有过这样的经历?
我在这里做了些什么愚蠢的行为?
任何帮助都很棒!
:)
问题是npm处理嵌套依赖的方式。当您安装my-gulp包时,目录树如下所示:
| myApp
| - node_modules
| - my-gulp
| - node_modules
| - gulp_dependency
正如您所看到的,my-gulp的依赖关系被隐藏在它自己的 node_modules
目录中。 myApp
无法访问它们。
您可以使用将其移动到顶层目录。否则,您将被迫将每个依赖项添加到 myApp
的package.json中。
编辑:
正如您的要点所示,您可以通过路径而不是软件包名称加载依赖关系。
// myApp / gulp文件,而不是复制您的gulp文件,只需从myApp中获取它的相关信息即可。 .js
require('my-gulp / gulpfile.js');
// my-gulp / gulpfile.js
var gulpDep = require('./ node_modules / gulp-dependency');
注意:如果您使用 npm dedupe
。
Here's what I want to do:
Create a node package that features the following:
gulpfile.js
- All gulp plugins, tasks, configs.
Install this node package (referred to as "my-gulp" from here on) within an Angular app (referred to as "myApp" from here on) via
package.json
dependencies.gulpfile.js
is copied into app root.- All Gulp tasks can be run from app.
We currently have something similar setup with Grunt (although without the Gruntfile.js
copy stuff). It works pretty well to have a common setup for each of our apps, but also several custom Bower components. Just have to bring it in as a dependency and it magically works.
The main issue I've run into so far is when I add my-gulp to myApp's dependencies, run the install, my-gulp comes in just fine, however the individual plugins (my-gulp dependencies) aren't seen. They're installed, but running something like gulp default
or whatever shows them missing.
I've tried to setup Gulp dependencies (in my-gulp) under "dependencies" as opposed to "devDependencies", yet still not quite working.
Does anyone have any experience doing something like this?Am I doing something blatantly stupid here?
Any help is awesome!
Thanks, everyone :)
The problem is the way npm handles nested dependencies. When you install your "my-gulp" package, the directory tree looks like this:
| myApp
|-- node_modules
|-- my-gulp
|-- node_modules
|-- gulp_dependency
As you can see, the dependencies of "my-gulp" are buried inside its own node_modules
directory. myApp
cannot access them.
You could use something like npm-flatten to move those to the top directory. Otherwise you'll be forced to add each dependency to myApp
's package.json.
Edit:As indicated in your gist, you can load the dependencies by path instead of package name. Instead of copying your gulpfile, simply require it from myApp, then load its dependencies with a relative path:
// myApp/gulpfile.js
require('my-gulp/gulpfile.js');
// my-gulp/gulpfile.js
var gulpDep = require('./node_modules/gulp-dependency');
Note: This won't work if you use npm dedupe
.
这篇关于是否有可能以分布式方式设置Gulp?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!