0

I'm using requireJS in Rails application with requirejs-rails gem. What I'm trying to achieve is to create several bundles which contain common code. For example libs_a, libs_b, libs_c, ... Then for some pages of the application create own bundles which contain modules related only to those pages. Problem is that all common modules should be listed for each page to exclude them from optimized files, like:

# config/requirejs.yml

modules:
  # in 'libs' all dependencies should be included
  - name: 'libs_a'
    ...
  - name: 'libs_b'
    ...
  - name: 'libs_c'
    ...
  # in 'pages' all dependencies should be excluded since all of them are already in 'libs'
  - name: 'page_a'
    include: ['a1', 'a2', 'a3', ...]
    exclude: ['libs_a', 'libs_b', 'libs_c', ...]
  - name: 'page_b'
    include: ['b1', 'b2', 'b3', ...]
    exclude: ['libs_a', 'libs_b', 'libs_c', ...]
bundles:
  libs_a: [...]
  libs_b: [...]
  libs_c: [...]
  ...

With large number of modules it becomes a bit cumbersome. As I understood there is no option to include in optimized file only those modules which are listed in build config and skip all dependencies. So that repeating exclude: ['libs_a',...] could be avoided. How do you solve such problem?

Babur Usenakunov
  • 1,965
  • 2
  • 16
  • 16

1 Answers1

0

Just an idea - It should be possible to define build config as a .js file. If you do that, you will be able to include simple logic to amend config with excluded libraries.

pavel_karoukin
  • 286
  • 3
  • 9