Is there any way to configure RequireJS to compile an entire directory to a single file? I don't mean the normal use case of the 'out' setting. I'll try to explain by example. If I have the following project structure:
- app
- main.js
- menu.js
- module
- file-a.js
- file-b.js
Then let's say I want to compile the 'app' directory to a single file. I don't care about it's dependencies - even if it requires 'module' or either of its files, they won't be included. Even if main.js doesn't require menu.js, it'll be included anyway. The resultant output file would define 'app/main' and 'app/menu' modules.
Likewise, if I wanted to compile the 'module' directory, the file would define 'module/file-a' and 'module/file-b' regardless of what other dependencies were defined.
I hope this is clear enough.
You can use the
dirparameter in build file of require instead of justnameparameter.You can read more about building whole directory on requirejs documentation - Optimize Whole Project
If you write build file something like
app-build.js-and if you run
r.js -o app.build.jsthen it will createHere
menu.jswill not be include inmain.jsunless it is required somewhere inmain.jssource.