browserify-hello-world

= Browserify hello world

Usage no npm install needed!

<script type="module">
  import browserifyHelloWorld from 'https://cdn.skypack.dev/browserify-hello-world';
</script>

README

= Browserify hello world

http://browserify.org/[Browserify] hello world example that exports a function for both browser and Node.js usage.

Basically answering: https://stackoverflow.com/questions/23296094/browserify-how-to-call-function-bundled-in-a-file-generated-through-browserify

Node.js development usage:

.... git clone https://github.com/cirosantilli/browserify-hello-world cd browserify-hello-world npm link npm link browserify-hello-world ./browserify-hello-world ....

Output:

.... 1 2 3 ....

Here, ./browserify-hello-world is a Node.js executable, and it sees our browserify_hello_world.myfunc function and calls it.

Browser usage:

.... npm run b ....

This runs:

.... npx browserify --outfile out.js --standalone browserify_hello_world index.js ....

which out.js, which is used in the link:index.html[] example with:

....

....

You can observe it:

.... xdg-open index.html ....

That page contains 1 2 3, which was also generated by our browserify-hello-world code just like the Node.js call.

As you can see, the cool thing about Browserify is that it recursively packs up all Node.js dependencies into the browser version of the JavaScript. Here as an example we imported the uniq library both on Node.js and browser.

Tested on Chromium 78, Ubuntu 19.10.