如何修复“任务不在您的 gulpfile 中"使用 npm 链接时出错? [英] How to fix "Task is not in your gulpfile" error when using npm link?
问题描述
我们有一堆共享通用 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 不再识别我们的任何自定义 gulp 任务.我运行的任何 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
开发"任务在我的 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;
这篇关于如何修复“任务不在您的 gulpfile 中"使用 npm 链接时出错?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!