如何解决“任务不在你的大文件中”使用npm链接时出错? [英] How to fix "Task is not in your gulpfile" error when using npm link?

查看:299
本文介绍了如何解决“任务不在你的大文件中”使用npm链接时出错?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有许多应用程序共享通用的gulp逻辑,所以我们制作了一个包含大量自定义任务的gulp插件。

We have a bunch of applications sharing common gulp logic, so we made a gulp plugin that contains a bunch of custom tasks.

然而,我们希望避免为我们开发的每个应用程序安装gulp +插件(以及一半的互联网)。

However we'd like to avoid installing gulp+our plugin (along with half the internet) for each of the applications we develop.

理想情况下,我想这样做:

Ideally, I'd like to do:

npm install -g gulp
npm install -g <our gulp plugin>

然后对于每个应用程序,我们只需要做:

Then for each app, we'd simply have to do:

npm link gulp
npm link <our gulp plugin>

虽然这可行,但问题是吞咽不再识别我们的任何自定义吞咽任务。我运行的任何gulp命令都会导致:

Although this works, the problem is gulp no longer recognizes any of our custom gulp tasks. Any gulp command I run results in:

[15:16:51] Using gulpfile /workspace/my-app/gulpfile.js
[15:16:51] Task 'dev' is not in your gulpfile
[15:16:51] Please check the documentation for proper gulpfile formatting

'dev'任务在我的gulp插件中,为什么不找到它?我的gulpfile.js只有这个:

The 'dev' tasks is in my gulp plugin, why isn't it finding it? My gulpfile.js only has this:

var gulp = require('gulp');
var mygulpplugin = require('mygulpplugin');

当gulp +插件在本地安装时,完全相同的过程可以工作。任何想法为什么?

The exact same process works when gulp + the plugin is installed locally. Any ideas why?

推荐答案

想通了。

Figured it out. Added the following line at the bottom of my module:

module.exports = gulp;

每个模块中的gulpfile如下所示:

And my gulpfile in each module looks like this:

var gulp = require('gulp'); 
var mygulpplugin = require('mygulpplugin');
gulp.tasks = mygulpplugin.tasks;

这篇关于如何解决“任务不在你的大文件中”使用npm链接时出错?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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