requisite
A cosmic javascript bundler.
Last updated 2 years ago by zeekay .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install requisite 
SYNC missed versions from official npm registry.

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

Current Tags

  • 1.19.17                                ...           latest (2 years ago)

201 Versions

  • 1.19.17                                ...           2 years ago
  • 1.19.16                                ...           3 years ago
  • 1.19.15                                ...           3 years ago
  • 1.19.14                                ...           3 years ago
  • 1.19.13                                ...           3 years ago
  • 1.19.12                                ...           3 years ago
  • 1.19.11                                ...           3 years ago
  • 1.19.10                                ...           3 years ago
  • 1.19.9                                ...           3 years ago
  • 1.19.8                                ...           3 years ago
  • 1.19.7                                ...           3 years ago
  • 1.19.6                                ...           3 years ago
  • 1.19.5                                ...           3 years ago
  • 1.19.4                                ...           3 years ago
  • 1.19.2                                ...           3 years ago
  • 1.19.1                                ...           3 years ago
  • 1.19.0                                ...           3 years ago
  • 1.18.11                                ...           3 years ago
  • 1.18.10                                ...           3 years ago
  • 1.18.9                                ...           3 years ago
  • 1.18.8                                ...           3 years ago
  • 1.18.7                                ...           3 years ago
  • 1.18.6                                ...           3 years ago
  • 1.18.5                                ...           3 years ago
  • 1.18.4                                ...           3 years ago
  • 1.18.3                                ...           4 years ago
  • 1.18.2                                ...           4 years ago
  • 1.18.1                                ...           4 years ago
  • 1.18.0                                ...           4 years ago
  • 1.17.9                                ...           4 years ago
  • 1.17.8                                ...           4 years ago
  • 1.17.7                                ...           4 years ago
  • 1.17.6                                ...           4 years ago
  • 1.17.5                                ...           4 years ago
  • 1.17.4                                ...           4 years ago
  • 1.17.3                                ...           4 years ago
  • 1.17.2                                ...           4 years ago
  • 1.17.1                                ...           4 years ago
  • 1.17.0                                ...           4 years ago
  • 1.16.1                                ...           4 years ago
  • 1.16.0                                ...           4 years ago
  • 1.15.2                                ...           4 years ago
  • 1.15.1                                ...           4 years ago
  • 1.15.0                                ...           4 years ago
  • 1.14.12                                ...           4 years ago
  • 1.14.11                                ...           4 years ago
  • 1.14.10                                ...           4 years ago
  • 1.14.9                                ...           4 years ago
  • 1.14.8                                ...           4 years ago
  • 1.14.7                                ...           4 years ago
  • 1.14.6                                ...           4 years ago
  • 1.14.5                                ...           4 years ago
  • 1.14.4                                ...           4 years ago
  • 1.14.3                                ...           4 years ago
  • 1.14.2                                ...           4 years ago
  • 1.14.1                                ...           4 years ago
  • 1.14.0                                ...           4 years ago
  • 1.13.6                                ...           4 years ago
  • 1.13.5                                ...           4 years ago
  • 1.13.4                                ...           4 years ago
  • 1.13.3                                ...           4 years ago
  • 1.13.2                                ...           4 years ago
  • 1.13.1                                ...           4 years ago
  • 1.13.0                                ...           4 years ago
  • 1.12.1                                ...           4 years ago
  • 1.12.0                                ...           4 years ago
  • 1.11.5                                ...           4 years ago
  • 1.11.4                                ...           4 years ago
  • 1.11.3                                ...           4 years ago
  • 1.11.2                                ...           4 years ago
  • 1.11.1                                ...           4 years ago
  • 1.11.0                                ...           4 years ago
  • 1.10.7                                ...           4 years ago
  • 1.10.6                                ...           4 years ago
  • 1.10.5                                ...           4 years ago
  • 1.10.4                                ...           4 years ago
  • 1.10.3                                ...           4 years ago
  • 1.9.17                                ...           4 years ago
  • 1.10.1                                ...           4 years ago
  • 1.10.0                                ...           4 years ago
  • 1.9.16                                ...           4 years ago
  • 1.9.15                                ...           4 years ago
  • 1.9.14                                ...           4 years ago
  • 1.9.13                                ...           4 years ago
  • 1.9.12                                ...           4 years ago
  • 1.9.11                                ...           4 years ago
  • 1.9.10                                ...           4 years ago
  • 1.9.9                                ...           4 years ago
  • 1.9.8                                ...           4 years ago
  • 1.9.7                                ...           4 years ago
  • 1.9.6                                ...           4 years ago
  • 1.9.5                                ...           4 years ago
  • 1.9.4                                ...           5 years ago
  • 1.9.2                                ...           5 years ago
  • 1.9.1                                ...           5 years ago
  • 1.9.0                                ...           5 years ago
  • 1.8.10                                ...           5 years ago
  • 1.8.9                                ...           5 years ago
  • 1.8.8                                ...           5 years ago
  • 1.8.7                                ...           5 years ago
  • 1.8.6                                ...           5 years ago
  • 1.8.5                                ...           5 years ago
  • 1.8.4                                ...           5 years ago
  • 1.8.2                                ...           5 years ago
  • 1.8.1                                ...           5 years ago
  • 1.8.0                                ...           5 years ago
  • 1.7.9                                ...           5 years ago
  • 1.7.8                                ...           5 years ago
  • 1.7.7                                ...           5 years ago
  • 1.7.6                                ...           5 years ago
  • 1.7.5                                ...           5 years ago
  • 1.7.4                                ...           5 years ago
  • 1.7.2                                ...           5 years ago
  • 1.7.1                                ...           5 years ago
  • 1.7.0                                ...           5 years ago
  • 1.6.10                                ...           5 years ago
  • 1.6.9                                ...           5 years ago
  • 1.6.8                                ...           5 years ago
  • 1.6.7                                ...           5 years ago
  • 1.6.6                                ...           5 years ago
  • 1.6.5                                ...           5 years ago
  • 1.6.4                                ...           5 years ago
  • 1.6.3                                ...           5 years ago
  • 1.6.2                                ...           5 years ago
  • 1.6.1                                ...           5 years ago
  • 1.6.0                                ...           5 years ago
  • 1.5.14                                ...           5 years ago
  • 1.5.13                                ...           5 years ago
  • 1.5.12                                ...           5 years ago
  • 1.5.11                                ...           5 years ago
  • 1.5.9                                ...           6 years ago
  • 1.5.8                                ...           6 years ago
  • 1.5.7                                ...           6 years ago
  • 1.5.6                                ...           6 years ago
  • 1.5.5                                ...           6 years ago
  • 1.5.4                                ...           6 years ago
  • 1.5.3                                ...           6 years ago
  • 1.5.2                                ...           6 years ago
  • 1.5.1                                ...           6 years ago
  • 1.5.0                                ...           6 years ago
  • 1.4.9                                ...           6 years ago
  • 1.4.8                                ...           6 years ago
  • 1.4.6                                ...           6 years ago
  • 1.4.5                                ...           6 years ago
  • 1.4.4                                ...           6 years ago
  • 1.4.3                                ...           6 years ago
  • 1.4.2                                ...           6 years ago
  • 1.4.1                                ...           6 years ago
  • 1.4.0                                ...           6 years ago
  • 1.3.3                                ...           6 years ago
  • 1.3.2                                ...           6 years ago
  • 1.3.1                                ...           6 years ago
  • 1.2.3                                ...           6 years ago
  • 1.2.1                                ...           6 years ago
  • 1.2.0                                ...           6 years ago
  • 1.1.8                                ...           6 years ago
  • 1.1.7                                ...           6 years ago
  • 1.1.6                                ...           6 years ago
  • 1.1.5                                ...           6 years ago
  • 1.1.4                                ...           6 years ago
  • 1.1.3                                ...           6 years ago
  • 1.1.2                                ...           6 years ago
  • 1.1.1                                ...           7 years ago
  • 1.1.0                                ...           7 years ago
  • 1.0.11                                ...           7 years ago
  • 1.0.10                                ...           7 years ago
  • 1.0.9                                ...           7 years ago
  • 1.0.8                                ...           7 years ago
  • 1.0.7                                ...           7 years ago
  • 1.0.6                                ...           7 years ago
  • 1.0.5                                ...           7 years ago
  • 1.0.4                                ...           7 years ago
  • 1.0.2                                ...           7 years ago
  • 1.0.1                                ...           7 years ago
  • 1.0.0-beta4                                ...           7 years ago
  • 1.0.0-beta2                                ...           7 years ago
  • 1.0.0-beta                                ...           7 years ago
  • 0.3.8                                ...           7 years ago
  • 0.3.7                                ...           7 years ago
  • 0.3.6                                ...           7 years ago
  • 0.3.5                                ...           7 years ago
  • 0.3.4                                ...           7 years ago
  • 0.3.3                                ...           7 years ago
  • 0.3.2                                ...           7 years ago
  • 0.3.1                                ...           7 years ago
  • 0.3.0                                ...           7 years ago
  • 0.2.11                                ...           7 years ago
  • 0.2.10                                ...           7 years ago
  • 0.2.9                                ...           7 years ago
  • 0.2.8                                ...           7 years ago
  • 0.2.7                                ...           7 years ago
  • 0.2.6                                ...           7 years ago
  • 0.2.5                                ...           7 years ago
  • 0.2.4                                ...           7 years ago
  • 0.2.3                                ...           7 years ago
  • 0.2.2                                ...           7 years ago
  • 0.2.1                                ...           7 years ago
  • 0.2.0                                ...           7 years ago
  • 0.1.2                                ...           7 years ago
  • 0.1.1                                ...           7 years ago
  • 0.1.0                                ...           7 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 202
Last Day 0
Last Week 202
Last Month 2
Dependencies (37)
Dev Dependencies (17)

Copyright 2014 - 2017 © taobao.org |