Frage

I have a problem with requiring programmatically created modules for browserify.

var File = require("vinyl"),
    browserify = require("browserify");

bundler = browserify();
bundler.require(new File({contents: new Buffer(...)}), {expose: "mymodule"});

bundler.bundle();
...

In the output file i have the content of buffer, but not exposed to "mymodule".

Does anybody used this case?

War es hilfreich?

Lösung

This was a bug in browserify, but was fixed with this patch: https://github.com/substack/node-browserify/pull/907

and your above code should work in version 6.0.1 and above

Andere Tipps

Since this question was posted James Halliday (substack, creator of browserify) has been hard at work coming up with the browserify handbook: https://github.com/substack/browserify-handbook

This resource is excellent. It goes really deep into how requires work and resolve dependencies in general. It is by far the best resource I have ever seen on the subject. Perhaps if you (or anyone else landing on this question with a similar problem) give it a read, the answer might jump out at you.

I know it's not a direct answer to your question, but I only recently found this resource, and I wish I knew it existed earlier.

For an introduction to browserify, I recommend watching this tagtree video: http://tagtree.tv/browserify-an-intro?share_code=uncoopered-inspirer

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top