I know this is a very old question, but for the sake of completeness I'll mention the option of going with Browserify. It allows you to build your project as different modules using NPM's require
function to resolve dependencies, and then it resolves those dependencies and concatenates your entire project into an single file.
For example, say your project is called FooBar and you want to output a file called foobar.js
. You'd create a main.js
file as the entry point for the project, requiring all the modules that should be included.
main.js
require("./doFoo");
require("./doBar");
Then run:
browserify main.js -o foobar.js
Or, to do it automatically every time a source file changes you could also use Watchify.
watchify main.js -o foobar.js
Browserify will also resolve dependencies between modules. So for example, if doBar.js depends on doQux.js
...
doBar.js
require("./doQux");
const doBar = ()=>{
//Do some bar stuff.
}
exports.doBar = doBar;
Then Browserify will make sure to include doQux.js
into foobar.js
so that you won't have any broken dependencies.