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

后端 未结 2 893
时光说笑
时光说笑 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)
    0 讨论(0)
  • 2021-02-13 19:28

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

    module.exports = gulp;
    

    And my gulpfile in each module looks like this:

    var gulp = require('gulp'); 
    var mygulpplugin = require('mygulpplugin');
    gulp.tasks = mygulpplugin.tasks;
    
    0 讨论(0)
提交回复
热议问题