Search code examples
javascriptrequire

Javascript require Method within another require method


(Someone may change the title accordingly) What happens exactly when javascript's require method is called like this:

var xyz = require('xy')(require('z'));

thank you


Solution

  • var gulp = require('gulp-help')(require('gulp')); works because require('gulp-help') returns you a function and then that takes the module exported by gulp as an argument, along with the options

    like

    require('gulp-help')(require('gulp'), options);
    
    These are all the options available to be passed to the gulp-help instance, NOT individual tasks.
    
    description - modifies the default help message
    aliases - adds aliases to the default help task
    hideEmpty - hide all tasks with no help message defined. Useful when including 3rd party tasks
    hideDepsMessage - hide all task dependencies
    afterPrintCallback - a function to run after the default help task runs
    

    This is a short form for

    var gulp-help = require('gulp-help');
    var gulp = gulp-help(require('gulp'));