browserify / browserify-handbook

how to build modular applications with browserify
Other
4.58k stars 292 forks source link

External bundles #30

Closed ebrehault closed 6 years ago

ebrehault commented 9 years ago

As explain here: https://github.com/substack/browserify-handbook#external-bundles I do the following:

npm install jquery
browserify -r jquery --standalone jquery > jquery-bundle.js
browserify main.js --exclude jquery > bundle.js

index.html:

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>My Site</title>
  <script src="jquery-bundle.js"></script>
  <script src="bundle.js"></script>
</head>
<body>
    <h1>My Site</h1>
</body>
</html>

main.js:

var $ = require('jquery');
$(window).click(function () { document.body.bgColor = 'red' });

And when I open my page I get Uncaught Error: Cannot find module 'jquery'

Is it a code bug, a doc bug or am I just missing something ?

rubennorte commented 9 years ago

I think the documentation is wrong. If you replace "--exclude" with "--external" it'll work fine.

sh1989 commented 9 years ago

I've also tried to reproduce the handbook's excluding example and ran into the same issue, using Browserify v11.0.0. However, using --external instead of --exclude, as suggested by @rubennorte doesn't work either.

In both cases, you get the "Cannot find module 'jquery'" error. Any further suggestions?

sh1989 commented 9 years ago

The following incantation worked for me:

browserify -r jquery > jquery-bundle.js (no standalone!) browserify main.js -x jquery > bundle.js (where -x is shorthand for --external)

nornagon commented 9 years ago

I experienced the same issues as @sh1989, and discovered the same fix. Would be nice to get the docs updated, I'll make a PR

tschaub commented 8 years ago

See #62 for an alternative fix.

$ browserify -r jquery --standalone jQuery > jquery-bundle.js