Reputation: 63
I want to use Browserify to add a couple files to one bundle. I have one "app.js" file, and a "config.js" file. 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:
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 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? If so, how would I add both the app.js and config.js into the bundle.js?
Thanks all
Upvotes: 1
Views: 1819
Reputation: 201
When you run browserify app.js
in your CLI, Browersify treats app.js
as the entry point. 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
.
By specifying var config = require("./config");
, you're telling Browersify to look in ./config
for a module.exports
, return that code and assign to var config
.
This is a solid, lengthier explanation of what I posted: https://benclinkinbeard.com/posts/how-browserify-works/
Upvotes: 2