gulp-multi-thread-task

2.1.0 • Public • Published

Node.js Package Node.js CI

Installation

npm install gulp-multi-thread-task --save-dev

What is gulp-multi-thread-task?

gulp-multi-thread-task is a simple and easy way to transform a gulp task into a task which is runs on multiple threads

Benefits

  • Blazing Fast - non blocking file processing, threads will always be provided files until all files have been processed.
  • Optimized - seamlessly add multi-core support to a gulp task, will only spawn a thread once and reuse the same thread unlike gulp-multi-process which spawns a new thread per task.
  • Simple - Easy to transform a existing task into a multi-threaded task.

Why?!

node is a single thread, and almost all machines have multiple cores, this plugin allows your gulp task run time to be drastically improved by magnitudes by the number of threads used.

Example

const gulp = require('gulp')
const imagemin = require('gulp-imagemin');
const texturePacker = require('gulp-free-tex-packer');
const {GulpMultiThreadTask} = require('gulp-multi-thread-task');

function buildSprites(done, src) {
    return gulp.src(src)
        .pipe(texturePacker()
        .pipe(imagemin())
        .pipe(gulp.dest());
}

function gulpBuildSprites(done, gameName = userOptionGameName) {
    return GulpMultiThreadTask(['assets/**/*.*(svg|png|jpg|jpeg)'], buildSprites);  
}

// example multiple glob array to batch file process
// you can batch a group of files together to create a single stream process
function gulpBuildSpritesGames {
    return GulpMultiThreadTask('build:sprites', [
            ['assets/**/game1/**/*.*(svg|png|jpg|jpeg)'],
            ['assets/**/game1/**/*.*(svg|png|jpg|jpeg)']
        ], buildSprites
    );  
}

gulp.task('build:sprites', gulpBuildSpritesGames)

API

GulpMultiThreadTask(taskName, globArray, gulpFunction, options);

taskName

Type: string

The registered task to multi-thread

globArray

Type: Array

The glob pattern of file that will be processed by gulpFunction

gulpFunction

Type: Function

gulp style function which will run on multiple threads, required parameters gulpFunction(done, src)

Options

concurrency

Type: number Default: Math.min(os.cpus().length / 2, processedGlobArray.length)

The number of threads to use.

silent

Type: boolean Default: false

Whether or not to send output to parent's stdio

Package Sidebar

Install

npm i gulp-multi-thread-task

Weekly Downloads

10

Version

2.1.0

License

MIT

Unpacked Size

50.3 kB

Total Files

15

Last publish

Collaborators

  • ctsiakouris