Skip to content
This repository has been archived by the owner on Mar 23, 2024. It is now read-only.

Exclude module dependencies in layered builds doesn't seem to work #30

Closed
jmaicher opened this issue Jan 21, 2012 · 7 comments
Closed

Comments

@jmaicher
Copy link

Not sure if this relates to #20.

I have a module common which is related to all pages:

define(['jquery'], function($) {
  // ...
});

Each page has a separate module, f.e. page1:

define(['jquery', 'some_other_dep'], function($) {
  // ...
});

My requirejs.yml looks like this:

modules:
  - name: "common"
  - name: "page1"
    exclude: ["common"]

If I precompile my assets, then jquery should only be included in the optimized version of common.
Instead jquery is included in both, common and page1.

I assume this is has to do with the rjs_driver and how it builds a series of individual files. A comment says something about "async builds". What exactly do you mean by that?

@karellm
Copy link
Contributor

karellm commented Jan 24, 2012

Hey Julian,

I think you should exclude: ["jquery"] because common isn't a dependency of your page1.js.


Though, I have the following solution that doesn't seem to work:

My app.js: define["module1", "module2"], { // ... })

My module1.js: define["ckeditor/ckeditor", { //... })

My requirejs.yml:

paths:
  ckeditor: "ui/ckeditor"
modules:
  - name: 'app'
    exclude: ['ckeditor/ckeditor']

Though, ckeditor is still included. I tried to exclude ckeditor with ckeditor, ui/ckeditor/ckeditor and ckeditor/ckeditor. None seems to work.

Any clue?

@karellm
Copy link
Contributor

karellm commented Jan 24, 2012

I created a fork up until John merges or fixes it:

#31

If you want to test it, replace the requirejs-rails line in your gemfile with:
gem 'requirejs-rails', :git => 'https://github.com/karellm/requirejs-rails'

@jmaicher
Copy link
Author

Thanks for you bugfix @karellm.

Take a look at the example in the docs: http://requirejs.org/docs/faq-optimization.html#priority

If I exclude common then the optimized page1 module shouldn't include common's modules and their nested dependencies.

@karellm
Copy link
Contributor

karellm commented Jan 24, 2012

Indeed it makes a lot of sense as it excludes all dependencies of the excluded module. Thanks for the info.

@phoenix-scitent
Copy link

I've also experienced this problem. The exclude directive doesn't seem to work for either direct dependencies or their nested dependencies. My workaround has been to force exclusion at the module level by declaring dependencies using variables, as per the example on http://requirejs.org/docs/optimization.html .

@karellm
Copy link
Contributor

karellm commented Jan 26, 2012

That is a nice workaround but my fork fixes the bug in the gem directly so your code can remain clean of any hack.

@jwhitley
Copy link
Owner

Hi all. I'm going get a fix for this into the next release, which I expect to kick out over the weekend. @karelim, thanks for pull request #31. I'll review that and pull it assuming that I have no feedback/changes.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants