0

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.

Barguast
  • 5,032
  • 6
  • 36
  • 67

1 Answers1

-1

You can use the dir parameter in build file of require instead of just name 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-

({
   appDir: ".",
   baseUrl: "app",
   dir: "../app-build",
})  

and if you run r.js -o app.build.js then it will create

  • app-build
    • main.js
    • menu.js

Here menu.js will not be include in main.js unless it is required somewhere in main.js source.

Community
  • 1
  • 1
shriidhar
  • 407
  • 3
  • 15
  • It doesn't have the single file output though, which is what I'm after. I've already got Traceur creating the AMD code. Now I just want to create my bundles for each part of the project. – Barguast Nov 17 '14 at 19:34