Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

require() with BrowserFS

NotificationsYou must be signed in to change notification settings

Narazaka/browserfs-module.js

Repository files navigation

npmnpm licensenpm download totalnpm download by monthBowerBower

Dependency StatusdevDependency StatusTravis Build StatusAppVeyor Build StatusCode Climate

TheNode.js'require() on the browser!

Motivation

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()?

Install

npm:

npm install browserfs-module

bower:

bower install browserfs-module

Usage

node ./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>

License

This is released underMIT License.

About

require() with BrowserFS

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp