Skip to content
This repository was archived by the owner on Jun 10, 2025. It is now read-only.

API reference

Rich-Harris edited this page Sep 20, 2014 · 11 revisions

node = gobble( 'foo' )

Returns a node object representing the contents of the 'foo' directory.

node = gobble([ node1, node2[, ...nodeN] ])

Returns the result of merging the input nodes. Later files overwrite earlier ones.

node2 = node1.transform( transformer, options )

Returns a tree that is the result of applying transformer to node1. See Writing plugins for more information.

node.inspect( 'tmp/some-dir'[, options] )

Sometimes it's useful, for debugging purposes, to dump part of your build to disk in order to inspect it. This method will continuously write the contents of node to 'tmp-some-dir' whenever they change, as long as Gobble is running. It returns this, so it doesn't affect the build in any way - it's just a convenient way to see what's going on.

If you pass { clean: true } as the second argument, the target folder will be emptied, otherwise existing files will be left alone.

Built-in transforms

There are a handful of built-in transforms:

node.include( patterns )

Filters out any files that don't match patterns. patterns can be a minimatch string, or an array of them.

node.exclude( patterns )

Opposite of node.include(patterns).

node.grab( subdirectory )

Grab all the files in the specified subdirectory. For example, if src/assets were a directory with an images subdirectory, you could do this:

assets = gobble( 'src/assets' );
images = assets.grab( 'images' );

images would now contain the contents of src/assets/images.

node.moveTo( subfolder )

The opposite of node.grab():

pub = gobble([ images, fonts, otherStuff ]).moveTo( 'public' );
Clone this wiki locally