gulp-multi-thread-task
Version:
Takes a gulp task and make's it run in multiple threads to improve build time
89 lines (61 loc) • 2.73 kB
Markdown
<p align="center">
<img height="257" width="458" src="./artwork/gulp-multi-thread-task-2x.png">
</p>


```npm install gulp-multi-thread-task --save-dev```
**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](https://www.npmjs.com/package/gulp-multi-process#warning) which spawns a new thread per task.
- **Simple** - Easy to transform a existing task into a multi-threaded task.
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.
```
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)
```
```GulpMultiThreadTask(taskName, globArray, gulpFunction, options);```
Type: `string`
The registered task to multi-thread
Type: `Array`
The glob pattern of file that will be processed by 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