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

roli-sprockets-commonjs

Package Overview
Dependencies
Maintainers
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

roli-sprockets-commonjs

  • 0.0.10
  • Rubygems
  • Socket score

Version published
Maintainers
2
Created
Source

ROLI Sprockets CommonJS

This library adds CommonJS support to Sprockets.

A fork of maccman's library, which is sadly no longer maintained.

What is CommonJS?

The CommonJS module format is a way of encapsulating JavaScript libraries, ensuring they have to explicitly require and export properties they use. In a nutshell:

  1. You require in files using require():
var asset = require('models/asset');
  1. You export properties using module.exports:
var asset = function(){ /* ... */ };
module.exports = Asset;

This library

This library adds CommonJS support to Sprockets, so it can wrap up JavaScript files as modules, and serve them appropriately. This is done by giving any JS files you want as modules, the .module.js extension.

Sprockets will then wrap up the JS library when it's requested, with the following:

require.define({'library/name': function(exports, require, module){
  /* Your library */
}});

require.define() is defined inside commonjs.js, which you'll need to include in the page before any modules are loaded.

// Inside application.js
//
// require_tree .

One caveat to the approach this library takes, is that dependencies loaded through require() will not be added to the dependency graph. This library will not parse the AST tree for require calls. This decision has been made for a variety of reasons, but it does mean you need to require files through both CommonJS and Sprockets.

Usage

  1. Add gem "roli-sprockets-commonjs" to your Gemfile
  2. Add .module.js to any JavaScript files you want as modules, i.e. users.module.js
  3. Require all the modules, e.g.: //= require_tree ./models
  4. Or, require individual modules, e.g.: //= require users.module

FAQs

Package last updated on 09 Mar 2016

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