npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

grunt-changed

v3.0.0

Published

Run Grunt tasks with only those source files where the content changed to the last run.

Downloads

3,230

Readme

grunt-changed

Build Status npm

Configure Grunt tasks to run with changed file contents only.

Synopsis: The changed task will configure another task to run with src files that have a) different content than on the previous run (based on md5 hash). See below for examples and more detail. This library is heavily inspired by and based on grunt-newer

Getting Started

This plugin requires at least Grunt 0.4.1 and is also compatible to version 1.0.0

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a gruntfile.js as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install grunt-changed --save-dev

Once the plugin has been installed, it may be enabled inside your gruntfile.js with this line:

grunt.loadNpmTasks('grunt-changed');

The changed task

The changed task doesn't require any special configuration. To use it, just add changed as the first argument when running other tasks.

For example, if you want to use Uglify to minify your source files only when one or more of them is changed compared to the previous run, configure the uglify task as you would otherwise, and then register a task with changed at the front.

  grunt.initConfig({
    uglify: {
      all: {
        files: {
          'dest/app.min.js': ['src/**/*.js']
        }
      }
    }
  });

  grunt.loadNpmTasks('grunt-contrib-uglify');
  grunt.loadNpmTasks('grunt-changed');

  grunt.registerTask('minify', ['changed:uglify:all']);

With the above configuration the minify task will only run uglify if one or more of the src/**/*.js files changed after the last run.

The changed task can also be used with tasks that don't generate any dest files.

For example, if you want to run 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 changed at the front.

  grunt.initConfig({
    jshint: {
      options: {
        jshintrc: '.jshintrc'
      },
      all: {
        src: 'src/**/*.js'
      }
    }
  });

  grunt.loadNpmTasks('grunt-contrib-jshint');
  grunt.loadNpmTasks('grunt-changed');

  grunt.registerTask('lint', ['changed:jshint:all']);

With the above configuration, running grunt lint will configure your jshint:all task to use only files in the jshint.all.src config that have been modified since the last successful run of the same task. The first time the jshint:changed:all task runs, all source files will be used. After that, only the files you modify will be run through the linter.

Another example is to use the changed task in conjunction with watch. For example, you might want to set up a watch to run a linter on all your .js files whenever one changes. With the changed task, instead of re-running the linter on all files, you only need to run it on the files that changed.

  var srcFiles = 'src/**/*.js';

  grunt.initConfig({
    jshint: {
      all: {
        src: srcFiles
      }
    },
    watch: {
      all: {
        files: srcFiles,
        tasks: ['changed:jshint:all']
      }
    }
  });

  grunt.loadNpmTasks('grunt-contrib-jshint');
  grunt.loadNpmTasks('grunt-contrib-watch');
  grunt.loadNpmTasks('grunt-changed');

With the above configuration, running grunt jshint watch will first lint all your files with jshint and then set up a watch. Whenever one of your source files changes, the jshint task will be run on just the modified file.

Options for the changed task

In most cases, you shouldn't need to add any special configuration for the changed task. Just grunt.loadNpmTasks('grunt-changed') and you can use changed as a prefix to your other tasks. The options below are available for advanced usage.

options.cache

  • type: string
  • default: node_modules/grunt-changed/.cache

To keep track of timestamps for successful runs, the changed task writes to a cache directory. The default is to use a .cache directory within the grunt-changed installation directory. If you need timestamp info to be written to a different location, configure the task with a cache option.

Example use of the cache option:

  grunt.initConfig({
    changed: {
      options: {
        cache: 'path/to/custom/cache/directory'
      }
    }
  });

That's it

Please submit an issue if you encounter any trouble. Contributions or suggestions for improvements welcome!

Known limitations

The changed task relies on Grunt's convention for specifying src/dest mappings. So it should be expected to work with two types of tasks:

Tasks that specify src files: The task prefixed by changed will be configured to run with src files that have changed content to the last run (based on md5 hash of files).