- Notifications
You must be signed in to change notification settings - Fork1
Narazaka/browserfs-module.js
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
TheNode.js'require() on the browser!
Browsers do not support therequire() API on Node.js, since they do not have File Systems. (And we are playing with magicrequire() processors, like webpack).
But we can make fake File System on browsers by usingBrowserFS.
Now, why not use the realrequire()?
npm:
npm install browserfs-modulebower:
bower install browserfs-modulenode ./foo.js corresponds toModule._load ('./foo.js').
You can userequire() in./foo.js just like on Node.js.
<scriptsrc="browserfs.js"></script><scriptsrc="browserfs-module.js"></script><script>varfsBase=newBrowserFS.FileSystem.InMemory();BrowserFS.initialize(fsBase);varfs=BrowserFS.BFSRequire('fs');fs.writeFileSync('/main.js','module.exports = require("sub");');fs.mkdirSync('/node_modules');fs.writeFileSync('/node_modules/sub.js','module.exports = "sub required!";');Module=browserfsModule.Module;varmain=Module._load("/main");console.log(main);// "sub required!"</script>
This is released underMIT License.
About
require() with BrowserFS
Topics
Resources
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
No packages published
Uh oh!
There was an error while loading.Please reload this page.