
Security News
GitHub Actions Checkout Now Blocks Risky pull_request_target Checkouts
GitHub Actions checkout now blocks risky pull_request_target checkouts by default to help prevent pwn request supply chain attacks.
gulp-load-utils
Advanced tools
Recommended Gulp utilities wrapped up conveniently without creating an unnecessary dependency tree.
This is a fork of gulp-util, sharing much of the same code. Use instead of gulp-util to load only the utilities you want, as well as other recommended packages.
You'll need the devDependencies in your package.json for the utils you request, which are listed with each utlity below. If you try to use a utility which you hadn't requested, or you request one without its dependencies installed, an error will be thrown telling you what's missing.
npm install --save-dev gulp-load-utils
Also npm install or add to package.json the devDependencies you need, as listed below.
Pass the properties of gutil you want to use like so:
var gutil = require('gulp-load-utils')(['colors', 'env', 'log', 'pipeline']);
// Run `gulp --production`
var isProduction = gutil.env.production;
if(isProduction) {
gutil.log( 'Building for', gutil.colors.magenta('production') );
gutil.beep();
}
// [gulp] [23:09:09] Building for production *system beep*
This keeps your code cleaner and loads less dependencies as opposed to starting with:
var gutil = require('gulp-util');
var colors = require('chalk');
var env = require('minimist')(process.argv.slice(2));
var pipeline = require('multipipe');
Suggested usage with gulp-load-plugins:
var $ = require('gulp-load-plugins')();
var _ = $.loadUtils(['log', 'colors']);
_.log( _.colors( ... ) );
Trigger a system beep. No dependencies, always present.
| devDependencies | through2 |
This is similar to es.wait but instead of buffering text into one string it buffers anything into an array (so very useful for file objects).
Returns a stream that can be piped to.
The stream will emit one data event after the stream piped to it has ended. The data will be the same array passed to the callback.
Callback is optional and receives two arguments: error and data
gulp.src('stuff/*.js')
.pipe(gutil.buffer(function(err, files) {
});
An instance of chalk.
| devDependencies | chalk |
Use when logging values with gutil.log.
gutil.log( gutil.colors.red('Red text!'));
An instance of node-dateformat.
| devDependencies | dateformat |
Using gutil.log prefixes the output with this already, as HH:MM:ss.
var header = 'Compiled on ' + gutil.date('mmm d, yyyy h:MM:ss TT Z');
// Compiled on Mar 7, 2014 5:09:09 PM EST
An instance of vinyl-source-stream.
| devDependencies | vinyl-source-stream |
Use to convert regular text streams to the vinyl file streams used by Gulp. Pass a fake filename/path to control the destination.
See the watchify recipe for an example.
See minimist.
| devDependencies | minimist |
// Run `gulp --type production`
var isProduction = gutil.env.type === 'production';
An instance of vinyl.
| devDependencies | vinyl |
var file = new gutil.File({
base: join(__dirname, './fixtures/'),
cwd: __dirname,
path: join(__dirname, './fixtures/test.coffee')
});
Returns true or false if an object is a stream. No dependencies, always present.
Returns true or false if an object is a Buffer. No dependencies, always present.
An instance of lazypipe.
| devDependencies | lazypipe |
Combine streams in a reusable manner.
var jsTasks = gutil.lazypipe()
.pipe(compileJS, jsOpts)
.pipe(minifyJS)
;
gulp.task('scripts', function() {
return gulp.src('src/**/*.js')
.pipe(jsTasks())
.pipe(gulp.dest('dist/'));
});
| devDependencies | chalk, dateformat |
Prefixes the message with [gulp] and the current time. Multiple arguments are joined with a space, just like console.log. Use the right colors for values.
values (files, module names, etc.) = magenta
numbers (times, counts, etc) = cyan
gutil.log( 'Something happened in', gutil.colors.magenta(file), 'after', gutil.colors.cyan(count), 'things');
| devDependencies | through2 |
Returns a stream that does nothing but pass data straight through.
gulp.task('scripts', function() {
gulp.src('src/**/*.js')
.pipe(isProduction ? minifyJS() : gutil.noop())
.pipe(gulp.dest('dist/');
});
An instance of multipipe.
| devDependencies | multipipe |
Use to combine streams, apply events to them. For a reusable approach use gutil.lazypipe.
gulp.task('scripts', function() {
return gutil.pipeline(
gulp.src('src/**/*.js'),
compileJS(),
minifyJS(),
gulp.dest('dist/')
).on('error', errHandler);
});
| devDependencies | chalk |
options.showStack to true if you think the stack is important for your error.These are all acceptable forms of instantiation:
var err = new gutil.PluginError('test', {
message: 'something broke'
});
var err = new gutil.PluginError({
plugin: 'test',
message: 'something broke'
});
var err = new gutil.PluginError('test', 'something broke');
var err = new gutil.PluginError('test', 'something broke', {showStack: true});
var existingError = new Error('OMG');
var err = new gutil.PluginError('test', existingError, {showStack: true});
An instance of replace-ext.
| devDependencies | replace-ext |
Replaces a file extension in a path. Returns the new path.
var filepath = '/some/dir/file.js';
var newpath = replaceExt(filepath, '.coffee');// /some/dir/file.coffee
| devDependencies | lodash.template, lodash._reinterpolate |
This is a lodash.template function wrapper. You must pass in a valid gulp file object so it is available to the user or it will error. You can not configure any of the delimiters. Look at the lodash docs for more info.
var opt = {
name: 'todd',
file: someGulpFile
};
gutil.template('test <%= name %> <%= file.path %>', opt) // test todd /js/hi.js
```
[travis-url]: https://travis-ci.org/DSKrepps/gulp-load-utils
[travis-image]: https://travis-ci.org/DSKrepps/gulp-load-utils.png?branch=master
FAQs
Conveniently wrapped utility functions for working with gulp
The npm package gulp-load-utils receives a total of 89 weekly downloads. As such, gulp-load-utils popularity was classified as not popular.
We found that gulp-load-utils demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
GitHub Actions checkout now blocks risky pull_request_target checkouts by default to help prevent pwn request supply chain attacks.

Product
Socket now supports Custom Roles and Repository Access Permissions so organizations can control who can access specific repositories and actions.

Product
Socket MCP now lets AI assistants review org alerts, investigate threats using the Socket threat feed, and inspect package files in addition to dependency scoring.