Frage

I'm working with a couple of node.js modules that I require on the client:

index.js:

var sync = require('../lib/sync');

So I figured browserify might be the best choice. Bundling the files works great, however, browserify wraps everything in a (function(){my code here})(); which cause the Can't find variable: require error. How can I prevent that behaviour?

When I remove the wrap, everything works as expected without errors.

War es hilfreich?

Lösung

I run browserify with "--exports require", would this be what you need?

browserify entry.js --exports require -o br.js

Andere Tipps

You can pass parameters to the IIFE like this:

(function (require) {
    var sync = require('../lib/sync');
}(requre));
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top