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

requisite

v1.19.17

Published

A cosmic javascript bundler.

Downloads

295

Readme

requisite

npm build dependencies downloads license chat

Cosmic JavaScript bundling

Want ES module support? See Handroll.

Introduction

Requisite bundles client-side code and templates. It features asynchronous module loading for optimal performance of large applications, automatic compiler detection for several languages and comes with a connect/express middleware for rapid development.

Features

  • Use CommonJS modules in the browser.
  • Customizable compiler/preprocessors.
  • Simple API for programmatic usage.
  • Lazy asset loading.
  • Resolves relative as well as npm modules.
  • Command line tool for bundling simple projects.
  • Good Source map support.

Install

npm install -g requisite

Modules

Requiste allows you to structure your code using CommonJS (Node.js) modules. From a given starting point or entry module, requisite will trace your application's dependencies and bundle all require'ed modules together. Requiste's require supports asynchronous loading of assets/modules when an optional callback argument is provided.

// foo.js
module.exports = 'foo';

// async-bar.js
module.exports = 'bar'

// entry.js
console.log(require('./foo'))  // 'foo'
require('./async-bar', function(bar) {
    console.log(bar) // 'bar'
})

This compiles down to:

// ...prelude, defining require, etc.

require.define('/foo', function (module, exports, __dirname, __filename) {
    module.exports = 'foo';
})

require.define('/main', function (module, exports, __dirname, __filename) {
    console.log(require('/foo'));
    require('/async-bar', function(bar) {
        console.log(bar);
    })
})

Note how async-bar.js is missing from the bundle, as it's loaded at runtime.

If you are writing a module that can be used both client/server side you can define the browser field in your package.json and finetune which bits will be bundled for the client.

Usage

CLI

› requisite

Usage: requisite [options] [files]

Options:

  -h, --help                   display this help
  -v, --version                display version
  -a, --async                  prelude should support async requires
  -b, --bare                   compile without a top-level function wrapper
  -d, --dedupe                 deduplicate modules (when multiple are specified)
  -e, --export <name>          export module as <name>
  -i, --include <module>       additional module to include, in <require as>:<path to module> format
  -g, --global                 global require
  -m, --minify                 minify output
      --minifier               minifier to use
  -o, --output <file>          write bundle to file instead of stdout, {} may be used as a placeholder
  -p, --prelude <file>         file to use as prelude
      --no-prelude             exclude prelude from bundle
      --no-source-map          disable source maps
      --prelude-only           only output prelude
  -s, --strict                 add "use strict" to each bundled module
      --strip-debug            strip `alert`, `console`, `debugger` statements
  -w, --watch                  write bundle to file and and recompile on file changes
  -x, --exclude <regex>        regex to exclude modules from being parsed
      --base                   path all requires should be relative to

Examples:

  # bundle javascript file and all it's dependencies
  $ requisite module.js -o bundle.js

  # bundle several modules, appending .bundle.js to output
  $ requisite *.js -o {}.bundle.js

Examples

Bundle a javascript file and all it's dependencies:

$ requisite module.js -o bundle.js

Create several bundles, appending .bundle.js to each entry module's name:

$ requisite *.js -o {}.bundle.js

Create a single shared bundle (to leverage caching in browser) and individual bundles for each page containing just the additional modules necessary for each:

$ requisite --dedupe main.js page1.js page2.js -o {}.bundle.js

You'd then use the bundle across the pages of your site like so:

// page1.js
<script src="main.bundle.js">
<script src="page1.bundle.js">

// page2.js
<script src="main.bundle.js">
<script src="page2.bundle.js">

// page3.js
<script src="main.bundle.js">
<script src="page3.bundle.js">

API

If you want more fine-grained control over requisite you can require it in your own projects and use it directly.

    require('requisite').bundle({
        entry: __dirname + '/entry.js',
    }, function(err, bundle) {
        fs.writeFileSync('app.js', bundle.toString())
    });

Middleware

For development it can be useful to serve bundles up dynamically, and a connect middleware is provided for exactly this purpose. Express example:

  app.use('/js/app.js', require('requisite').middleware({
    entry: __dirname + '/entry.js'
  }))

Which would make your bundle available as http://host/js/main.js.

License

MIT