Skip to content
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

External bundles #30

Closed
ebrehault opened this issue Nov 21, 2014 · 5 comments
Closed

External bundles #30

ebrehault opened this issue Nov 21, 2014 · 5 comments

Comments

@ebrehault
Copy link

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
Copy link

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

@sh1989
Copy link

sh1989 commented Jul 23, 2015

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
Copy link

sh1989 commented Jul 23, 2015

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
Copy link
Contributor

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
Copy link

tschaub commented Oct 8, 2015

See #62 for an alternative fix.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants