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 🙏

© 2026 – Pkg Stats / Ryan Hefner

sp-load

v1.1.0

Published

Modules loader. No lots of require calls on the top of files. On demand modules loading. Local modules.

Readme

sp-load

Description

  • Do you hate lots of require calls on the top of your files?
  • Do you want to have on demand modules loading(lazy loading)?
  • Do you want to have local modules instead of using absolute or relative paths for getting modules?

If the answer is "yes" - the sp-load is what you need! Just read "usage" section and I think you will like this module.

Install

$ npm install --save-dev sp-load

Usage

The simplest usage. For example you have package.json file, here is its content:

{
    "name": "your-project",
    "version": "1.0.0",
    "main": "index.js",
    "dependencies": {
        "lodash": "^3.10.1",
        "sp-load": "^1.0.0"
    },
    "devDependencies": {
        "gulp": "^3.9.0",
        "webpack": "^1.12.9"
    },
    "_localDependencies": {
        "core": "./core/core",
        "some-module": "./deep/deep/deep/deep/deep/deep/deep/some-module"
    },
    "_coreDependencies": {
        "path": "path",
        "fs": "fs"
    }
}

And you have the next files structure:

your-project/
    node_modules
        sp-load/
            ...
        gulp/
            ...
        lodash/
            ...
        webpack/
            ...
    package.json
    core/
        core.js
    deep/
        deep/
            deep/
                deep/
                    deep/
                        deep/
                            deep/
                                some-module.js
    gulpfile.js
    index.js

Here is content of gulpfile.js:

'use strict';

var $ = require('sp-load'),
    webpackConfig = {};

$.gulp.task("webpack", function (callback) {
  $.webpack(webpackConfig, function (err, stats) {
    callback();
  });
});

Here is content of some-module.js:

'use strict';

function someModuleFuction() {
    console.log('I\'m some module function call!');
}

module.exports = someModuleFuction;

Here is content of core.js:

'use strict';

function coreModuleFuction() {
    console.log('I\'m core module function call!');
}

module.exports = coreModuleFuction;

Here is content of index.js:

'use strict';

var $ = require('sp-load');

$.someModule();

$.core();

As you can see all you need to do is "require('sp-load')". It returns object, which contains list of on demand modules. These modules will be loaded only when you call module name from the object, for example module "gulp" will be loaded at the moment when you first call $.gulp(...);

Also as you can see in package.json there is a property "_localDependencies". In this property you can define local modules of your project. Just define module name as key and path of module as value. Path must be relative to package.json file.

Also as you can see in package.json there is a property "_coreDependencies". In this property you can define core modules of nodejs, for example "path" or "fs" modules. Just define module name as key and anything as value. Value is not used but must be defined, so "path": "path" and "path": "abcdefg" will work equally.

If you want to use modules without using "$" object, you can do like in the next examples. Here is example with using "es6 destructuring assignment". To use es6 features in node js, read node js documenation how to turn on "es6":

'use strict';

var {someModule, core} = require('sp-load');

someModule();

core();

Here is example with using "es5":

'use strict';

var $ = require('sp-load'),
    someModule = $.someModule,
    core = $.core;

someModule();

core();

Advanced usage

You can configure sp-load. Just add "_sp-load" property in package.json. Here is example of package.json with configs(description of each config option see in comments):

{
    "name": "your-project",
    "version": "1.0.0",
    "main": "index.js",
    "dependencies": {
        "lodash": "^3.10.1",
        "sp-load": "^1.0.0"
    },
    "devDependencies": {
        "gulp": "^3.9.0",
        "webpack": "^1.12.9"
    },
    "_localDependencies": {
        "core": "./core/core",
        "some-module": "./deep/deep/deep/deep/deep/deep/deep/some-module"
    },
    "_coreDependencies": {
        "path": "path",
        "fs": "fs"
    },
    "_sp-load": {
        /*
            if true, modules names will be transformed to camel case,
            for example $.someModule instead of $['some-module'].
            default value is true.
        */
        "camelizing": false,
        /*
            this option renames modules names. for example instead of $.lodash, lodash module will be available as $._
        */
        "renaming": {
            "lodash": "_",
            "gulp": "supergulp"
        },
        /*
            if you want to replace some part of modules names use this option. The key is regular expression(regexp),
            the value is a replace string. For example you have gulp plugins. The names of most gulp plugins start with
            "gulp-" prefix, for example "gulp-concat". And you want to use this plugin as $.concat instead of
            $.gulpConcat
        */
        "replacing": {
            "/^gulp-/": ""
        }
    }
}

Maybe you do not want to put configs and local and core modules lists to package.json, you can create _sp-load.json and put this file to package.json file directory.

yourProject/
    package.json
    _sp-load.json

Here is example of package.json:

{
    "name": "your-project",
    "version": "1.0.0",
    "main": "index.js",
    "dependencies": {
        "lodash": "^3.10.1",
        "sp-load": "^1.0.0"
    },
    "devDependencies": {
        "gulp": "^3.9.0",
        "webpack": "^1.12.9"
    }
}

Here is example of _sp-load.json:

{
    "_localDependencies": {
        "core": "./core/core",
        "some-module": "./deep/deep/deep/deep/deep/deep/deep/some-module"
    },
    "_coreDependencies": {
        "path": "path",
        "fs": "fs"
    },
    "_sp-load": {
        "camelizing": false,
        "renaming": {
            "lodash": "_",
            "gulp": "supergulp"
        },
        "replacing": {
            "/^gulp-/": ""
        }
    }
}

Also when you do var $ = require('sp-load');, the object $ has property "_spModulesList" in its prototype object. It contains object where the keys are modules names(external, core and local modules) and the values are modules paths. For local modules paths are absolute paths to modules files. For core and external modules paths are modules names. For examples(camelizing option is set to false):

{
    "path": "path",
    "fs": "fs",
    "lodash": "lodash",
    "sp-load": "sp-load",
    "gulp": "gulp",
    "webpack": "webpack",
    "core": "D://your-project//core//core.js",
    "some-module": "D://your-project//deep//deep//deep//deep//deep//deep//deep//some-module.js"
}

It may be usefull if you want for example to load some local module using System.js loader.