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

v2.0.0

Published

Gruntplugin Lazy Loading

Downloads

31

Readme

grunt-lazyload

Gruntplugin Lazy Loading

The Api has been changed to extend the grunt object, rather than provide a new wrapping object. For documentation on the old api (v0.2.2 and below) go here: v0.2.2

Build Status NPM version Built with Grunt Code Climate

Getting Started

Install the module with: npm install grunt-lazyload --save

require('grunt-lazyload')(grunt);

grunt.lazyLoadNpmTasks('grunt-contrib-jshint', 'jshint');

Documentation

Lazy loading npm tasks means making every grunt run noticibly faster. For one of my projects it shaves almost 400ms off every run. Which when you want to just concat the file, is noticable. Or when you are trying to make your deploys as fast as possible, 400ms here can help keep things snappy.

Before Lazy Loading

Before Lazy Loading

After Lazy Loading

After Lazy Loading

(Image captured with time-grunt)

Another big win is if you are using grunt in conjunction with Jenkins to do your deploys. If you are lazy loading npm modules, modules that wont get triggered dont even need to be installed. So when jenkins starts running a job it runs npm install --production and only downloads the production dependencies and not the dev dependencies like grunt-contrib-watch for example. This means my npm install step during my deploys dropped from about 15 seconds to about 10. This was a big win for me and my team. Even when I have a full node_modules folder the check to see if anything needs updating dropped by 250ms by running npm install --production

Not everyone is using grunt the same way, but if you want your grunt to run a little bit faster, consider lazy loading.

Examples

Adding lazyloading to grunt:

require('grunt-lazyload')(grunt);

This is not truly a grunt plugin, but a node module that adds extra methods to grunt to allow lazy loading. Pass the instance of grunt you intend to extend.

Lazy loading an NPM library with a single task:

grunt.lazyLoadNpmTasks('grunt-contrib-jshint', 'jshint');

Lazy loading an NPM library with multiple tasks:

grunt.lazyLoadNpmTasks('grunt-some-plugin', ['task1', 'task2', 'task3']);

Lazy loading tasks from a local directory:

grunt.lazyLoadTasks('localdir/tasks', {
  'grunt-custombuild.js': 'custombuild',
  'grunt-deploy.js': ['deploy'],
  'grunt-customclean.js': ['clean', 'cleanall', 'reset'],
});

In order to initialize lazy loading, you must define ahead of time the possible task names and where to load them from. For lazyLoadNpmTasks, specify the task (or tasks) that are provided by that NPM module. For a local directory of tasks, provide a hash, where each key is the exact filename containing the tasks, and the value is the task (or tasks) it provides.

Task renaming

grunt.lazyLoadNpmTasks('grunt-contrib-copy', 'copy');
grunt.renameTask('copy', 'classic-copy');

// Later
grunt.task.run('classic-copy:somefiles');

Task renames are automatically tracked by the lazy loader and saved for later resolution. In this example, when you attempt to run classic-copy, the lazy loader will load grunt-contrib-copy and register the copy task as classic-copy.

Automatic task renaming works for both NPM tasks and local task directories.

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.

Release History

  • 5/10/2014 - 1.0.3 (eagerload for -h) - PR#5
  • 2/17/2014 - 1.0.2 (jshint error cleanup - PR#4)
  • 2/4/2014 - 1.0.1 (eagerload for the --help screen)
  • 2/4/2014 - 1.0.0 (simplify code and improve api)
  • 2/3/2014 - 0.2.2 (fix multitarget/paramater passing bug)
  • 5/14/2013 - 0.2.0 (use an init function to pass in the grunt object)
  • 5/14/2013 - 0.1.0
  • 5/10/2013 - 0.0.6 (gruntplugin keyword added to npm)
  • 5/10/2013 - 0.0.4 (Better tests)
  • 5/9/2013 - 0.0.2

License

Copyright (c) 2013 Raphael Eidus Licensed under the MIT license.