You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
sn0w 53b8cbe429 Update 1 year ago
lib Modernize project a bit 1 year ago
.gitignore Init 2 years ago
LICENSE Create LICENSE 2 years ago Update 1 year ago
index.js Modernize project a bit 1 year ago
package.json Modernize project a bit 1 year ago
yarn.lock Modernize project a bit 1 year ago


A 5000 lines long Gulpfile.js is so 2015 :eyes:



gulp-autoload was created out of pure frustration while working on a project in my company.
The Gulpfile.js had grown to a real beast and the first 45 lines of the file were just require calls.
I wanted something more modular and decided to revamp the structure a bit.



Executes the autoloader.
Takes an optional config object.

Note: The order in which files are processed is undefined.
It might be lexicographical but on some operating systems / environments it could be not ordered at all.
You should thus make no assumptions about the processing order and require() the submodules you depend on yourself.

These are the available config options:

    // The path where your gulp scripts are saved
    path:         <string> [optional] [default="./gulp.d"] 
    // An object that is passed to your gulp scripts
    moduleConfig: <object> [optional] [default={}]  
    // Enables (a lot of) debug logging
    debug:        <bool>   [optional] [default=false]      


There are multiple ways to store and pass config values to your tasks.
You can use and mix all of them at the same time.


Inline configs are simply passed to the gulp-autoload constructor.

let moduleConfig = {
    foo: "bar"



File-based configs override inline configs.
When “booting”, gulp-autoload will search your configured path for a _config.js or file.

This file must export an object with arbitrary content.
When both a _config.js and file are present, the behaviour is undefined.

module.exports = {
    foo: "bar"


  • Create a Gulpfile.js that requires and executes the autoloader
  • Create the folder that will contain your scripts
mkdir gulp.d
  • Create a or _config.js in gulp.d

This file is used to store all needed configuration of your gulp setup.
This may be anything from paths/destinations, environments, to api keys or whatever else you want.

It is required that this file exports an object.
The content is up to you and will be passed (unprocessed) to all registered gulp modules.

module.exports =
        src: "www/src/js"
        dst: "www/dist/js"
  • Create a gulp module in gulp.d

Gulp modules can be written in coffeescript or javascript.
The autoloader only recognizes files with .js or .coffee extensions.
If you need support for other languages see the “Special Cases” below.

Example that uglifies javascript:

gulp = require("gulp")
pump = require("pump")

module.exports = config ->
  gulp.task "js", cb ->
    ], cb)
  • Run your tasks as usual (eg gulp js)

  • Profit!

Special Cases

Note that there are two forms of valid gulp modules:

  • An exported function/closure that takes a config argument and will be executed by gulp-autoload
module.exports = function(config) {
    // do stuff when gulp-autoload is ready.
  • Side Effects

If your module does not export a function the autoloader assumes that the require() call had side effects and will do nothing with the returned values. This is included for convenience when, for example, chainloading other autoloaders or language-injection hooks like lispyscript/lib.


// compile-styles.js
// An example of how implicit side-effects can be used to chainload
// a different file and transpile it to javascript on the fly.

// Register a lisp-transpiler for example

// Chainload compile-styles.lisp

// Notice the missing module.exports.
// By not exporting anything at all, or exporting null,
// We tell gulp-autoload to trust our side-effects.
;; compile-styles.lisp
;; This module will be chainloaded by the code above

(var gulp (require "gulp"))

(set module.exports 
    (function () (
        (gulp.task "compile-styles" (function(cb) (
            ;; do stuff with gulp