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

smartload-grunt-tasks

v0.1.2

Published

Load multiple grunt tasks dynamically using globbing patterns. Load only the tasks you need based on the current task being run.

Downloads

2

Readme

smartload-grunt-tasks

Load multiple grunt tasks dynamically using globbing patterns. Load only the tasks you need based on the current task being run.

Usually you would have to load each task one by one, which is unnecessarily cumbersome. And despite only running a single build task, Grunt loads every single task which can add a second or more if it's a big project. Tell it to only load the one(s) you need based on what is being run.

This module will read the dependencies/devDependencies/peerDependencies in your package.json and load grunt tasks that match the provided patterns.

Before

Load everything you might possibly need in your Gruntfile.js

grunt customtask:dev

require(__dirname + '/grunt/tasks/customTask.js');
require(__dirname + '/grunt/tasks/customTask2.js');
require(__dirname + '/grunt/tasks/customTask3.js');
grunt.loadNpmTasks('grunt-shell');
grunt.loadNpmTasks('grunt-sass');
grunt.loadNpmTasks('grunt-recess');
grunt.loadNpmTasks('grunt-newer');
grunt.loadNpmTasks('grunt-contrib-imagemin');
grunt.loadNpmTasks('grunt-styl');

After

Let smartload-grunt-tasks load only what you need!

grunt customtask:dev

require('smartload-grunt-tasks')(grunt, {
	dir: 'grunt/tasks/',
	smartLoad: {
		'customtask:dev': ['customtask']
		'autoprefixer:sass': ['grunt-autoprefixer'],
		'newer:imagemin:assets_dev': ['grunt-newer', 'grunt-contrib-imagemin'],
	}
});

Install

$ npm install --save-dev smartload-grunt-tasks

Example config

// Gruntfile.js
module.exports = function (grunt) {
	// load all grunt tasks matching the `grunt-*` pattern
	require('smartload-grunt-tasks')(grunt, {

		// in which directory (if any) do you have custom tasks?
		// Each .js file will be require'd
		dir: 'grunt/tasks/',

		// which tasks should be loaded for each CLI task argument?
		smartLoad: {
			'customtask:dev': ['grunt-styl', 'customtask'],
			'autoprefixer:sass': ['grunt-autoprefixer'],
			'newer:imagemin:assets_dev': ['grunt-newer', 'grunt-contrib-imagemin']
		}
	});

	grunt.initConfig({});
	grunt.registerTask('default', []);
}

Usage examples

Load all grunt tasks

require('smartload-grunt-tasks')(grunt);

Equivalent to:

require('smartload-grunt-tasks')(grunt, {pkgPattern: 'grunt-*'});

Load all grunt-contrib tasks

require('smartload-grunt-tasks')(grunt, {pkgPattern: 'grunt-contrib-*'});

Load all grunt-contrib tasks, another non-contrib task, and every .js file in the grunt_tasks directory:

require('smartload-grunt-tasks')(grunt, {
	pkgPattern: ['grunt-contrib-*', 'grunt-shell'],
	dir: 'grunt_tasks'
});

Load all grunt-contrib tasks excluding one

You can exclude tasks using the negate ! globbing pattern:

require('smartload-grunt-tasks')(grunt, {pkgPattern: ['grunt-contrib-*', '!grunt-contrib-coffee']});

Set custom path to package.json

require('smartload-grunt-tasks')(grunt, {pkgConfig: '../package'});

Only load from devDependencies and when running the grunt task, only load grunt-contrib-sass task:

require('smartload-grunt-tasks')(grunt, {
	pkgScope: 'devDependencies',
	smartLoad: {
		'sass': ['grunt-contrib-sass']
	}
});

Only load from devDependencies and dependencies

require('smartload-grunt-tasks')(grunt, {pkgScope: ['devDependencies', 'dependencies']});

All options in use

require('smartload-grunt-tasks')(grunt, {
	pkgPattern: 'grunt-contrib-*',
	pkgConfig: '../package.json',
	pkgScope: 'devDependencies',
	dir: 'mycustomtasks/',
	dirPattern: '**/*.js',
	smartLoad: {
		'taskFromCLI': ['grunt-whatever']
	}
});

Options

Note: Since this was shamelessly stolen from and built upon load-grunt-tasks, it's backwards compatible; load-grunt-tasks' option keys will work here, too.

pkgPattern

Type: String, Array
Default: 'grunt-*' (globbing pattern)

pkgConfig

Type: String, Object
Default: Path to nearest package.json

pkgScope

Type: String, Array
Default: ['dependencies', 'devDependencies', 'peerDependencies']

dir

Type: String
Default: false (don't load any custom tasks)

dirPattern

Type: String
Default: '**/*.js

smartLoad

Type: Object
Default: false (load everything every time)

License

MIT