A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/janv/sprockets-browserify below:

janv/sprockets-browserify: Serve npm (CommonJS) modules through Sprockets with the help of Browserify.

Serve npm (CommonJS) modules through Sprockets with the help of Browserify.

Node.js, obviously. This gem calls node directly, no ExecJS involved.

Add this to your Gemfile:

gem 'sprockets-browserify'

Place a CommonJS Module in your assets directory and perform a npm install:

/app/assets/javascript/foo
  - index.js
  - package.json
  - node_modules/
    - ...

Require the module within your application.js or somewhere else:

//
//= require foo/index
//

Done.

Your node module should fulfill the following requirements:

If you want to use a module that doesn’t conform, consider creating a wrapper module in you assets directory that requires the module you actually want to use:

foo_wrapper/package.json:

...
"dependencies": {
  "foo": ...
},
...

foo_wrapper/index.js:

window.Foo = require('foo');

foo_wrapper/node_modules/foo/index.js:

module.exports = "Foo";

By default, the asset pipeline in Rails precompiles every file with a .js extension. This is probably not what you want if you have a bunch of modules in the node_modules directory. Disable this behavior by specifically listing only individual files you want to precompile:

config.assets.precompile = ['main.js', 'stylesheet.css']

instead of merely appending to

config.assets.precompile << 'main.js'

Released under the MIT License. See the MIT-LICENSE file for further details.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4