Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/437.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何访问我的捆绑包?_Javascript - Fatal编程技术网

Javascript 如何访问我的捆绑包?

Javascript 如何访问我的捆绑包?,javascript,Javascript,我有一个导出单个变量的脚本: module.exports = { hello: "world" }; 我正在绑定browserify,然后在我的index.html 这是我的html文件: <!DOCTYPE html> <html> <head> <title>Hello World</title> <script type="text/javascript" src="./b

我有一个导出单个变量的
脚本

module.exports = {
    hello: "world"
};
我正在绑定
browserify
,然后在我的
index.html

这是我的
html
文件:

<!DOCTYPE html>
<html>
    <head>
        <title>Hello World</title>
        <script type="text/javascript" src="./bundle.js"></script>
    </head>
    <body>
      <script>
        console.log(hello);
      </script>
    </body>
</html>

你好,世界
console.log(hello);
我发现我的变量
hello
未定义。我可以用我的开发工具看到
bundle.js
,所以我知道它就在那里。为什么正文中的
脚本
无法访问
bundle.js
正在导出的变量


我在这里遗漏了什么?

CMD
call中

browserify-r./bundle模块.js:bundle>bundle.js

bundle-module.js是您的原始模块代码

bundle module.js:bundle-冒号后面的“bundle”将在require调用中使用

bundle.js是browserify生成的代码

HTML

<!DOCTYPE html>
<html>
    <head>
        <title>Hello World</title>
        <script type="text/javascript" src="./bundle.js"></script>
    </head>
    <body>
      <script>
        var bundle = require('bundle');
        console.log(bundle.hello);
      </script>
    </body>
</html>

你好,世界
var bundle=需要(‘bundle’);
log(bundle.hello);

试试“var hello=“world”在您的文件中,
bundle.js
file locatedMy
bundle.js
与我的
index.html
位于同一级别,我试图声明
var hello='world'
,然后将其导出,但这没有帮助。您是否知道
module.exports
用于Node.js,不适用于浏览器端JavaScript?