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-tasks

v1.0.0

Published

Enables a more modular approach to configuring Grunt. Search a specified folder for files containing Grunt task definitions.

Downloads

105

Readme

Grunt Tasks

No more monolithic Gruntfile.

Gruntfiles typically have 4 sections:

  1. Define some variables to be interpolated into configuration later on.
  2. Configure some Grunt tasks.
  3. Load Grunt task modules. Example: grunt.loadNpmTasks('grunt-contrib-watch');
  4. Register some task aliases. Example: grunt.registerTask('js', ['jshint', 'concat', 'uglify']);

This can lead to rather lengthy Gruntfiles. The 'grunt-tasks' module allows to to break-up your Gruntfile into multiple modules organized any way you would like. It loads files containing Grunt task definitions via globbing patterns (#2). Variables (#1) and aliases (#4) can be set as object literals or can be specified as paths to .js files that contain those settings. It also uses the load-grunt-tasks module to automatically find and load npm Grunt modules (#3), and uses the time-grunt module to report on how long each task is taking to run.

Installation

Install with npm:

$ npm install --save-dev grunt-tasks

Usage

First, let's assume we have a file structure that looks like this:

  • grunt/
    • config.js
    • tasks/
      • dev.js
      • scripts.js
      • styles.js
  • lib/
  • public/
  • gruntfile.js
  • package.json

Now, our Gruntfile should be fairly simple. We require in 'grunt-tasks' and then in our exported function, we call 'grunt-tasks' with 2 parameters: 1) the 'grunt' object and 2) our options object. Example:

var gruntTasks = require('grunt-tasks');

module.exports = function(grunt) {
  gruntTasks(grunt, {
      tasks: 'grunt/tasks/*.js'
    , config: 'grunt/config.js'
    , aliases: {
          'js'       : ['concat:scripts', 'concat:cruxjs', 'uglify']
        , 'css'      : ['less', 'concat:styles', 'cssmin']
        , 'build'    : ['handlebars', 'css', 'js']
        , 'base'     : ['jshint', 'handlebars', 'less']
        , 'default'  : ['base', 'watch']
      }
  });
};

Take a look at the example folder of this package for a more detailed implementation example.

Property Merging

It's important to note that 'grunt-tasks' does a 2-level-deep merge of properties found in the task definition files. This means you can have a 'concat:css' task defined in one file and a 'concat:js' task in another. However, the sub-task name (ie, 'css' or 'js' in the previous example) must be unique, or one will overwrite the other.

Your config option (whether it's an object literal or a filepath) will be loaded before the tasks. Any matching properties in the task definition files will overwrite your configuration properties.

Options

tasks

Type: String | Array

Default: 'grunt/tasks/*.js'

The 'tasks' option should be a globbing pattern or a list of globbing patterns that map to your list of task definition modules.

config

Type: String | Object

Default: {}

Grunt allows you to set some config properties that are not necessarily task definitions. You can use these values in your task defintions as interpolated values using the <%= some.prop %> syntax. Use the 'config' option to configure those properties. Or you can specify a file path to a .js file that exports an object literal with the same properties.

aliases

Type: String | Object

Default: {}

For aliases, you can pass an object literal where the key is the name to be used for the task alias and the value is an array of task names. Or you can specify the path to a file that exports a similarly formed object.

exclude

Type: String | Array

Default: []

The globbing pattern(s) specifed for excludes will be excluded from your Grunt configuration. If you specify filepaths for the 'config' and/or 'aliases' options, those files will be automatically excluded; you don't need to list them here.

lgtOptions

Type: Object

Default: { pattern: ['grunt-', '@/grunt-*'] }

See the load-grunt-tasks documentation for configuration options.

License

Copyright (c) 2014 Marcus Ellis. See the LICENSE file for license rights and limitations (MIT).