requirejs-rails icon indicating copy to clipboard operation
requirejs-rails copied to clipboard

Misunderstanding about `modules` in requirejs.yml

Open StevenLangbroek opened this issue 11 years ago • 5 comments
trafficstars

I think I'm misunderstanding the modules node in requirejs.yml. The documentation says:

Pulled in via a dynamic require() call. Modules which are solely referenced by a dynamic require() call (i.e. a call not optimized by r.js) must be specified in the modules section in order to produce a correct build.

I've added a couple of modules in our requirejs.yml, like so:

modules:
  - name: 'main'
  - name: 'dash/dash'
  - name: 'page_controllers/applications'
  - name: 'page_controllers/category_blacklists'
  - name: 'page_controllers/companies'
  - name: 'page_controllers/mediations'
  - name: 'page_controllers/offer_filters'

However, when i set RAILS_ENV=production, and run $ bundle exec rake assets:precompile, they do not get compiled. The only file that gets optimised by r.js seems to be the main module. The page_controller modules are dynamically called in main.js, but those calls fail as they're not in public/assets. Any thoughts as to what's going on here?

StevenLangbroek avatar Sep 30 '14 17:09 StevenLangbroek

@StevenLangbroek You'll have to provide an example app for me to see what's going on. The description is not enough.

carsomyr avatar Sep 30 '14 21:09 carsomyr

@carsomyr I can't give you access to our repo (private). I'm not using the almond build, i tried settings digest to false in our deploy script, i've tried adding the modules to the priority node, but it just never compiles any other modules through r.js than the one we're loading through a requirejs_include_tag. Is that intended behavior?

StevenLangbroek avatar Oct 01 '14 08:10 StevenLangbroek

Ok, so I found out what's going on:

Our modules are in app/assets/javascripts/page_controllers. If I put them in app/assets/javascripts, and remove the folder name from requirejs.yml modules list, it works as expected.

So before:

modules:
  - name: 'main'
  - name: 'dash/dash'
  - name: 'page_controllers/applications'
  - name: 'page_controllers/category_blacklists'
  - name: 'page_controllers/companies'
  - name: 'page_controllers/mediations'
  - name: 'page_controllers/offer_filters'

after:

modules:
  - name: 'main'
  - name: 'dash'
  - name: 'controller_applications'
  - name: 'controller_category_blacklists'
  - name: 'controller_companies'
  - name: 'controller_mediations'
  - name: 'controller_offer_filters'

Think this is quite the caveat, and should maybe go into README.md. Thoughts?

StevenLangbroek avatar Oct 01 '14 10:10 StevenLangbroek

@StevenLangbroek That helps! I thought this issue was fixed a long time ago, but I'll take a second look.

carsomyr avatar Oct 01 '14 18:10 carsomyr

@StevenLangbroek @carsomyr do you know if this is happening with paths too?

eduardojmatos avatar Oct 07 '14 15:10 eduardojmatos