Browserify with require('fs') [英] Browserify with require('fs')

查看:133
本文介绍了Browserify with require('fs')的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在使用fs对象的文件上使用browserify。当我浏览它时,对 require('fs')的调用不会被转换,并且 require 返回 {}

有没有解决方法?我已经看到了stackoverlow和其他地方的一些建议,但没有一个似乎完全实现。



我真的希望创建一个谷歌网络打包的应用程序,使用browserify为一类教导。



预先感谢。

解决方案

浏览器使用呢? HTML5文件系统与传统文件系统并无真正的可比性。它没有符号链接,它只能在Web Workers之外异步访问。



所以答案是:自己编写一个抽象层,可以依赖fs模块在Node.js中运行,以及在浏览器中运行时的HTML5 FS API。差异太大,无法为您翻译浏览器。


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.

解决方案

Which filesystem should the browser use then? The HTML5 filesystem is not really comparable to a traditional filesystem. It doesn't have symlinks, and it is only accessible asynchronously outside Web Workers.

So the answer is: Write an abstraction layer yourself that can rely on the fs module when running in Node.js, and the HTML5 FS API when running in the browser. The differences are too large to have browserify translate for you.

这篇关于Browserify with require('fs')的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆