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

requirejs-configurator

v1.3.1

Published

A generic require.js configuration generator for npm style projects

Downloads

6

Readme

requirejs-configurator

A generic require.js map/package configuration generator. It can generate require.js from arbitrary package layout on disk.

requirejs-configurator is not intended as the best workflow in terms of web app development (check out webpack, browserify, Rave.js). It's more of a building block for other tools. It's quite a specialised package so to speak. It supports npm's package layout out of the box so it could prove to be useful for simple Require.js/Cajon based projects.

Programmatic usage

requirejs-configurator can be used to generate configuration for npm based projects.

var rc = require("requirejs-configurator");

There is a promise API

rc.npm("path/to/my/project").then(function () {
  console.log(config);
});

And the node style callback API

rc.npm("path/to/my/project", function (err, config) {
  console.log(config);
});

Use generate for more advanced use cases, e.g.

rc.generate({
  dependencies: ["foo@^1.0.0", "bar@*"],
  resolve: function (name, version, basedir, cb) {
    // npm config generator uses the `node-resolve` which uses node"s
    // `node_modules` traversal algorithm. By providing a custom resolver
    // it's possible to support different package layouts, e.g. a flat
    // structure with package@version directories, etc.
    cb(null path.resolve(__dirname, "base", name, version));
  }
});

Note that the options.resolve function can either take a callback or return a promise.

Command line usage

There's a small command line tool bundled with requirejs-configurator which can generate a configuration file for npm based projects, use it like so:

npm install -g requirejs-configurator

and then

requirejs-configurator --npm . > config.js

This assumes that node_modules will be served at your require.js baseUrl. If that's not the case, you'll have to use the programmatic API and modify the generated configuration by looping over the packages array and updating the location fields.

Include devDependencies

NPM package.json devDependencies can be included programatically:

```js
rc.npm("path/to/my/project", { includeDevDeps: true }).then(function () {
  console.log(config);
});

or

rc.npm("path/to/my/project", { includeDevDeps: true }, function (err, config) {
  console.log(config);
});

And using the CLI

```sh
requirejs-configurator --npm --include-dev-deps . > config.js

Example output

Here is what the output of generating configuration for requirejs-configurator itself looks like (+ Backbone just to demonstrate nested dependencies). With such configuration, it's then possible to call require("lodash") or require("[email protected]") or require("lodash@^2.4.1") and all nested dependencies are resolved correctly since they're configured in the map.

{
  map: {
    '[email protected]': {
      'underscore': '[email protected]'
    },
    '*': {
      'backbone': '[email protected]',
      'lodash': 'lodash@^2.4.1',
      'lodash@^2.4.1': '[email protected]',
      'ramda': 'ramda@^0.4.0',
      'ramda@^0.4.0': '[email protected]',
      'resolve': 'resolve@^1.0.0',
      'resolve@^1.0.0': '[email protected]',
      'when@^3.4.4': '[email protected]',
      'when': 'when@^3.4.4',
      'underscore@>=1.5.0': '[email protected]'
    }
  },
  packages: [{
    name: '[email protected]',
    main: 'backbone.js',
    location: 'node_modules/backbone'
  }, {
    name: '[email protected]',
    main: 'dist/lodash.js',
    location: 'node_modules/lodash'
  }, {
    name: '[email protected]',
    main: 'ramda.js',
    location: 'node_modules/ramda'
  }, {
    name: '[email protected]',
    main: 'index.js',
    location: 'node_modules/resolve'
  }, {
    name: '[email protected]',
    main: 'when',
    location: 'node_modules/when'
  }, {
    name: '[email protected]',
    main: 'underscore.js',
    location: 'node_modules/backbone/node_modules/underscore'
  }]
};

Example project

See a fully working example over here.