Using plugins with browserify

421 views Asked by At

I'm using ractive.js, an events plugin for it, ractive-events-keys, and browserify.

According to the usage for ractive-events-keys, I just need to require() it, and it'll install itself. That isn't working however. Upon closer inspection I realised I was getting two versions of ractive in my bundle (presumably because the plugin required it's own version), so I added a browser.ractive key to my package.json (kind of on a whim, but it seemed to work). I now only have one Ractive bundled, but the key event plugin still doesn't work (i.e., I still get the warning telling me to install the plugin).

As far as I know, I don't need browserify-shim, because the modules were designed to work with CommonJS.

How do I get it to work?

1

There are 1 answers

4
martypdx On

In my project, I have an index.js (browserify entry point) and load plugins like:

var Ractive = require('ractive');

// file reference:
/*var keys = */  require('./js/ractive-transitions-fade');

// npm reference:
/*var touch = */  require('ractive-touch');

var ractive = new Ractive({...})

The plugin "registers" itself, but you still have to "install" either as a file in your assets or via npm