How to fix “Task is not in your gulpfile” error when using npm link?

后端 未结 2 892
时光说笑
时光说笑 2021-02-13 18:25

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

However we\'d like to avoid installing gulp+o

2条回答
  •  有刺的猬
    2021-02-13 19:21

    Alternatively to the accepted answer, you can do it the way that was popular in grunt times, where you inject gulp to the plugin:

    In plugin: wrap everything with:

    module.exports = function(gulp) {
        gulp.task('foo', function () {
            ...
        })
        ...
    }
    

    and remove require('gulp') from the plugin's file.

    In gulpfile that depends on plugin you then do:

    var gulp = require('gulp');
    require('my-gulp-plugin')(gulp)
    

    That way

    • you can have multiple plugins in the main gulpfile, because you don't override gulp.tasks.
    • plugins don't have to declare gulp a package.json dependency in each of the plugins (less work for npm install)

提交回复
热议问题