UNPKG

3.2 kBMarkdownView Raw
1# grunt-concurrent [![Build Status](https://secure.travis-ci.org/sindresorhus/grunt-concurrent.png?branch=master)](http://travis-ci.org/sindresorhus/grunt-concurrent) [![Built with Grunt](https://cdn.gruntjs.com/builtwith.png)](http://gruntjs.com/)
2
3> Run grunt tasks concurrently
4
5Running slow tasks like Coffee and Sass concurrently can potentially improve your build time significantly. This task is also useful if you need to run multiple blocking tasks like `nodemon` and `watch` at once, as seen in the example config.
6
7![screenshot](screenshot.png)
8
9This task is similar to grunt-parallel, but more focused by leaving out support for shell scripts which results in a leaner config. It also has a smaller dependency size and pads the output of concurrent tasks, as seen above.
10
11
12## Getting Started
13
14If you haven't used [grunt][] before, be sure to check out the [Getting Started][] guide, as it explains how to create a [gruntfile][Getting Started] as well as install and use grunt plugins. Once you're familiar with that process, install this plugin with this command:
15
16```sh
17npm install grunt-concurrent --save-dev
18```
19
20Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
21
22```js
23grunt.loadNpmTasks('grunt-concurrent');
24```
25
26*Tip: the [load-grunt-tasks](https://github.com/sindresorhus/load-grunt-tasks) module makes it easier to load multiple grunt tasks.*
27
28
29[grunt]: http://gruntjs.com
30[Getting Started]: https://github.com/gruntjs/grunt/wiki/Getting-started
31
32
33## Documentation
34
35See the [Gruntfile](Gruntfile.js) in this repo for a full example.
36
37Just specify the tasks you want to run concurrently as an array in a target of this task as shown below.
38
39
40### Example config
41
42This will first run the Coffee and Sass tasks at the same time, then the JSHint and Mocha tasks at the same time.
43
44```javascript
45grunt.initConfig({
46 concurrent: {
47 target1: ['coffee', 'sass'],
48 target2: ['jshint', 'mocha']
49 }
50});
51
52grunt.loadNpmTasks('grunt-concurrent');
53grunt.registerTask('default', ['concurrent:target1', 'concurrent:target2']);
54```
55
56
57## Options
58
59### limit
60
61Type: `Number`
62Default: Number of CPU cores (`require('os').cpus().length`) with a minimum of 2
63
64Limit of how many tasks that are run concurrently.
65
66### logConcurrentOutput
67
68Type: `Boolean`
69Default: `false`
70
71You can optionally log the output of your concurrent tasks by specifying the `logConcurrentOutput` option. Here is an example config which runs [grunt-nodemon](https://github.com/ChrisWren/grunt-nodemon) to launch and monitor a node server and [grunt-contrib-watch](https://github.com/gruntjs/grunt-contrib-watch) to watch for asset changes all in one terminal tab:
72
73```javascript
74grunt.initConfig({
75 concurrent: {
76 target: {
77 tasks: ['nodemon', 'watch'],
78 options: {
79 logConcurrentOutput: true
80 }
81 }
82 }
83});
84
85grunt.loadNpmTasks('grunt-concurrent');
86grunt.registerTask('default', ['concurrent:target']);
87```
88
89*Note the output will be messy when combining certain tasks. This option is best used with tasks that don't exit like watch and nodemon to monitor the output of long-running concurrent tasks.*
90
91
92## License
93
94MIT © [Sindre Sorhus](http://sindresorhus.com)