Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I was trying to use browserify on a file that uses the fs object. When I browserify it, the call to require('fs') doesn't get transformed and require returns {}.

Is there any workaround for this? I've seen some suggestions on stackoverlow and elsewhere, but none seem to be fully realized.

I actually hoped to create a google web packaged app using browserify for a class I teach.

Thanks in advance.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
344 views
Welcome To Ask or Share your Answers For Others

1 Answer

If you want to inline file contents from fs.readFileSync() calls, you can use brfs:

var fs = require('fs');
var src = fs.readFileSync(__dirname + '/file.txt');

then do:

browserify -t brfs main.js > bundle.js

and src will be set to the contents of file.txt at compile time.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...