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
dir
parameter in build file of require instead of justname
parameter.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.js
then it will createHere
menu.js
will not be include inmain.js
unless it is required somewhere inmain.js
source.