Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

front-commonjs-require

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

front-commonjs-require

browser-side CommonJS require() function.

  • 1.4.6-1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
32
decreased by-45.76%
Maintainers
1
Weekly downloads
 
Created
Source

CommonJS Require

browser-side CommonJS require() function.

Usage

Add commonjs-require.js as script src to your site.

Example

<script src="commonjs-require.js"></script>
<script>
require.register("module", function(exports, require, module){
  /* Some Module content */
  module.exports = "content"
})
alert(require('module'))
</script>

This will alert content

Automated wrapping into require.register

Why not browserify?

Browserify requires (scnr) that you use some magic AST/require.resolve mechanism to built your CommonJS package/files for the browser. This is really complex - especially if you have to bundle different files for different sections of your website, use dynamic requires or have circular dependencies.

API

  • require(name) — loads registered module and returns its exports.
  • require.register(name, fn) — registers new module. fn should have signature exports, require, module.
  • require.list() — lists all registered modules.

Node Module support

commonjs-require emulates the actual loading mechanism from Node.js in that it delegates all require() calls to Module._load() (Module is exposed via the "module" module). This improves support for modules which rely on the Node module system implementation (for example Mockery).

Module API

  • Module._load(request, parent) - does the actual module loading and instantiation
  • Module._cache - is the cache of loaded modules, can be cleared by assigning an empty object
  • Module._resolveFilename - determines the actual module id (e.g. adds "index" if its missing)

License

MIT

Keywords

FAQs

Package last updated on 07 Dec 2015

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc