简体   繁体   English

Browserify将多个文件添加到bundle.js

[英]Browserify adding multiple files to bundle.js

I want to use Browserify to add a couple files to one bundle. 我想使用Browserify将几个文件添加到一个包中。 I have one "app.js" file, and a "config.js" file. 我有一个“ app.js”文件和一个“ config.js”文件。 The config has some connection endpoint info, and at the end has 该配置有一些连接端点信息,最后有

module.exports = config;

I'm not good with this stuff, but I am assuming this is needed so it can be referenced elsewhere. 我对这些东西不好,但是我假设这是必需的,因此可以在其他地方引用。

So my app.js file has some requires, like so: 所以我的app.js文件有一些要求,例如:

var documentClient = require("documentdb").DocumentClient;
var config = require("./config");
var url = require('url');

I know that with browserify I can do one file like their getting started tutorial by doing something like: 我知道使用browserify可以通过执行以下操作来制作一个文件,就像他们的入门教程一样:

browserify app.js --debug | exorcist bundle.map.js > bundle.js

I know I have some extra stuff in there, but my question is, wouldn't I also need to include the config.js in there, since it exports some config items that the app.js needs? 我知道我那里还有一些其他东西,但是我的问题是,我是否还不需要在其中包含config.js,因为它会导出app.js需要的一些配置项? If so, how would I add both the app.js and config.js into the bundle.js? 如果是这样,我如何将app.js和config.js都添加到bundle.js中?

Thanks all 谢谢大家

When you run browserify app.js in your CLI, Browersify treats app.js as the entry point. 当您运行browserify app.js在CLI,Browersify把app.js为切入点。 Each require statement in your code in app.js references a library that has some code that is returned via module.exports , Browserify traverses these libraries and concatenates all of the Javascript together in the final bundled output bundle.js . app.js中代码中的每个require语句都引用一个库,该库具有一些通过module.exports返回的代码,Browserify遍历这些库并将所有Javascript连接在一起,形成最终的捆绑输出bundle.js

By specifying var config = require("./config"); 通过指定var config = require("./config"); , you're telling Browersify to look in ./config for a module.exports , return that code and assign to var config . ,您告诉Browersify在./config查找一个module.exports ,返回该代码并分配给var config

This is a solid, lengthier explanation of what I posted: https://benclinkinbeard.com/posts/how-browserify-works/ 这是我发布的内容的坚实而冗长的解释: https : //benclinkinbeard.com/posts/how-browserify-works/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM