浏览器排除找不到模块

browserify exclude cannot find module

本文关键字:模块 找不到 排除 浏览器      更新时间:2023-09-26

我正在尝试让节点模块在浏览器中工作,但我不希望浏览器化在单独加载它时包含内联要求。

问题是,即使我正在加载带有<script>标签的超级代理,浏览器也会抛出异常: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')

苏斯.js

var superagent = require('superagent');
module.exports = { }

如何从浏览器中排除 require() 而不会引发异常?

我想通了...

browserify -i superagent --standalone iceberg source.js > output.js

然后在浏览器中只引用独立参数:

<script>
 iceberg.lettuce.eat();
</script>

http://www.forbeslindesay.co.uk/post/46324645400/standalone-browserify-builds