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

load-on-demand

v8.0.6

Published

on demand modules loading

Downloads

18

Readme

load-on-demand

Install

$ npm install --save-dev load-on-demand

Description

What is this module for? If you used modules gulp-load-plugins or lazy-modules or if you are looking for solution for on demand modules loading or you just hate lots of "require" on the top of files then this module is what you need. Using this module, you can load on demand modules from package.json file or your project modules.

In other words:

  • on demand modules
  • no lots of "require" on the top of files
  • no relative or absolute paths, all modules are available as "modules"

Usage

Imagine that you have the next files structure:

package.json
gulpfiles.js
node_modules/
    on-demand-modules/
                     index.js
gulp/
    configs/
        webpack.js
        gulp.js
    tasks/
         webpack.js
         jshint.js

Here is content of package.json:

{
    "dependencies": {
        "gulp-jshint": "*",
        "gulp-concat": "*",
        "glob": "^6.0.3",
        "lodash": "^3.10.1",
        "require-dir": "1.0.0"
    },
    "_additionalDependencies": {
        "path": true
    }
}

Here is content of node_modules/on-demand-modules/index.js(in this file you configure on demand modules):

'use strict';

/*
    var $ = {} will contain all on demand modules. you can use global object instead and all on demand modules will
    be available as global object properties, but I think it is better to use local object for avoiding any conflicts.
*/
var $ = {},
  projectPrefix = 'sp-', // this prefix will be added to your project modules, for example $.spWebpackConfig
  loadOnDemand = require('load-on-demand'),
  loadOnDemandSettingsList = {
    modulesInJsonFiles: [{ // here is settings for modulesInJsonFiles(modules from package.json)
      destination: $, // module which will contain all on demand modules
      /*
        there is also option modulesProperties. The default value is:
          defaultModulesProperties = [
            'dependencies',
            'devDependencies',
            'peerDependencies',
            '_additionalDependencies'
          ]
        using this option you can set json file properties names which contain modules lists

        there is also option filePath. The default value is:
        defaultFilePath = findup('package.json', {cwd: process.cwd()})
        using this option you can set json file(e.g. package.json)
      */
      formatting: { // options for formatting modules names
        renaming: {
            /*
                renaming is running before replacing and other formatting options.
            */
            'lodash': '_'
        },
        replacing: {
             /*
                replacing substrings in modules names(str.replace method is used). for example gulp-concat module
                will be now available as $.concat
             */
            '/^gulp(-|\.)/': ''
        }
        /*
            there is also option camelize(true by default). if set to true, then for example module my-module
            will be available as $.myModule, if set to false then $['my-module']
        */
      }
    }],

    modulesInFilesNames: [{ // here is settings for modulesInFilesNames(your project modules)
      destination: $,
      filesPathsPattern: './gulp/configs/*', // glob pattern of your project modules files
      formatting: {
        prefix: projectPrefix, // prefix and postfix will be added to modules names
        postfix: '-config'
      }
    }]
  };

loadOnDemand(loadOnDemandSettingsList);

module.exports = $;

/*
    so, after using loadOnDemand, $ object looks like:

    $.jshint
    $.concat
    $.glob
    $._
    $.path
    $.requireDir
    $.spWebpackConfig
    $.spGulpConfig
*/

Now you can require on-demand-modules in any file of your project. For example here is content of gulpfile.js:

'use strict';

var $ = require('on-demand-modules');

$.requireDir($.spGulpConfig.tasksFolder);

and here is content of gulp/configs/gulp.js:

'use strict';

var $ = require('on-demand-modules'),
  config = {
    tasksFolder: $.path.resolve(process.cwd(), './gulp/tasks')
  };

module.exports = config;

as you can see the module version is already 5.0.0(or maybe even more). It is just because it is almost my first npm module and I was making lots of changes when I wrote it. Lots of times I had to republish it, but when I did unpublish, anyway it was not allowed to republish module with the same version... :)