I am trying to get a node module to work in the browser, but I don't want browserify to include the require inline as I am loading it separately.
The problem is that even though I'm loading superagent with a <script>
tag, browserify throws an exception: Uncaught Error: Cannot find module superagent'
browserify --x superagent source.js -o output.js
script(src='/bower/superagent/superagent.js')
script(src='/js/output.js')
var superagent = require('superagent');
module.exports = { }
How can I exclude a require() from the browser without it throwing an exception?
I figured it out...
browserify -i superagent --standalone iceberg source.js > output.js
then in the browser just reference the standalone parameter:
<script>
iceberg.lettuce.eat();
</script>
http://www.forbeslindesay.co.uk/post/46324645400/standalone-browserify-builds
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.