UNPKG

3.27 kBMarkdownView Raw
1# grunt-newer
2
3Run [Grunt](http://gruntjs.com/) tasks with only the source files modified since the previous successful run.
4
5## Getting Started
6This plugin requires Grunt `~0.4.1`
7
8If you haven't used [Grunt](http://gruntjs.com/) before, be sure to check out the [Getting Started](http://gruntjs.com/getting-started) guide, as it explains how to create a [`gruntfile.js`](http://gruntjs.com/sample-gruntfile) as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:
9
10```shell
11npm install grunt-newer --save-dev
12```
13
14Once the plugin has been installed, it may be enabled inside your `gruntfile.js` with this line:
15
16```js
17grunt.loadNpmTasks('grunt-newer');
18```
19
20## The `newer` task
21
22The `newer` task doesn't take any special configuration. To use it, just add `newer` as the first argument when running other tasks.
23
24For example, if you want to run [JSHint](https://npmjs.org/package/grunt-contrib-jshint) on only those files that have been modified since the last successful run, configure the `jshint` task as you would otherwise, and then register a task with `newer` at the front.
25
26```js
27 grunt.initConfig({
28 jshint: {
29 options: {
30 jshintrc: '.jshintrc'
31 },
32 all: {
33 src: 'src/**/*.js'
34 }
35 }
36 });
37
38 grunt.loadNpmTasks('grunt-contrib-jshint');
39 grunt.loadNpmTasks('grunt-newer');
40
41 grunt.registerTask('lint', ['newer:jshint:all']);
42```
43
44With the above configuration, running `grunt lint` will configure your `jshint:all` task to use only files in the `src` config that have been modified since the last successful run of the same task.
45
46## The `any-newer` task
47
48The `newer` task described above reconfigures the target task to run with only those files that have been modified since the last run. This works well for tasks that don't generate new files (like linting). When you have a task that generates destination files based on configured source files, you likely want to process all source files if any one of them has been modified since the last run. The `any-newer` task serves this purpose.
49
50For example, if you want to run [UglifyJS](https://npmjs.org/package/grunt-contrib-uglify) on all your source files only when one or more have been modified since the last run, configure the `uglify` task as you would otherwise, and then register a task with `any-newer` at the front.
51
52
53```js
54 grunt.initConfig({
55 uglify: {
56 all: {
57 files: {
58 'dest/app.min.js': 'src/**/*.js'
59 }
60 }
61 }
62 });
63
64 grunt.loadNpmTasks('grunt-contrib-uglify');
65 grunt.loadNpmTasks('grunt-newer');
66
67 grunt.registerTask('minify', ['any-newer:uglify:all']);
68```
69
70With the above configuration, running `grunt minify` will only run the `uglify:all` task if one or more of the configured `src` files have been modified since the last successful run of the same task.
71
72## That's it
73
74Note that to keep track of successful runs, the `newer` task writes files in the `.grunt` directory where it is run. If you're running the task in a git repository, you'll want to add `.grunt` to your `.gitignore` file.
75
76[![Current Status](https://secure.travis-ci.org/tschaub/grunt-newer.png?branch=master)](https://travis-ci.org/tschaub/grunt-newer)