New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Documentation really sketchy on how to export a module #382
Comments
If you have a foo.js: module.exports = 555 and want
Now you can <script src="bundle.js"></script>
<script>
var foo = require('foo');
console.log(foo);
</script> which is the same as:
However, it's more common to just put the part that does main.js:
Then just put a single script tag into your page: <script src="bundle.js"></script> |
Thank you for the workaround example! I do have to ask, why is the that common case so complicated? You'll have to make a whole fake directory structure and copy your code there for just building a regular library that exports regular functions to be used both with Node and in the browser. A related question, the |
To make The global |
Umm, I get your simplicity point, but that shouldn't make exporting the library in the current working directory that difficult and inelegant. What's with the target option to You're right, I was reading the code wrong and assumed the |
I've been going back and forth the
README
and code for a while now trying to understand how the damn this is supposed to be used for exposing a module in the browser.The beep-poop example and
README
mention of a--require
flag but that even fails in the example'sbuild.sh
asrobot.js
is not a module in./node_modules
, but just a file.Then an attempt to use
--require
with a relative path ends up meaning you'll have to userequire("./foo")
in the browser as well, as opposed to just usingrequire("foo")
. Oh, hey,Optionally use a colon separator to set the target.
, but that's not even implemented according to #319?!Symlink the name of your library to your
index.js
and relative--require
that? Well, that prints out peculiar useless intermediary requires named in the style of"l5QO1E"
.So, how do you package an existing
index.js
file so you can dorequire("foo")
in the browser?The text was updated successfully, but these errors were encountered: