Security News
New Proposed CISA Mandate Would Require Critical Infrastructure to Report Ransom Payments Within 24 Hours
CISA has proposed a set of new rules that would require critical infrastructure to report cyber incidents and ransom payments.
requisite
Advanced tools
A cosmic javascript bundler.
Weekly downloads
Readme
Cosmic JavaScript bundling
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.
npm install -g requisite
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.
› 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
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">
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())
});
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
.
FAQs
A cosmic javascript bundler.
The npm package requisite receives a total of 13 weekly downloads. As such, requisite popularity was classified as not popular.
We found that requisite demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISA has proposed a set of new rules that would require critical infrastructure to report cyber incidents and ransom payments.
Security News
Redis is no longer OSS, breaking its explicit commitment to remain under the BSD 3-Clause License forever. This has angered contributors who are now working to fork the software.
Product
Socket AI now enables 'AI detected potential malware' alerts by default, ensuring users benefit from AI-powered state-of-the-art malware detection without needing to opt-in.