documentcloud / jammit

Industrial Strength Asset Packaging for Rails
http://documentcloud.github.com/jammit/
MIT License
1.16k stars 197 forks source link

is it possible to combine multiple packages in one file? #140

Closed favrik closed 13 years ago

favrik commented 13 years ago

For example:

<%= include_javascripts :welcome, :uploads %>

turns into: <script src="/assets/combined.js" type="text/javascript"></script>

instead of: <script src="/assets/welcome.js" type="text/javascript"></script>

<script src="/assets/uploads.js" type="text/javascript"></script>

Thanks!

vandrijevik commented 13 years ago

favrik, if you'd like to have the files in those two packages in one concatenation, why don't you just put them in one package?

In my opinon, this request defeats the purpose of packages to begin with.

favrik commented 13 years ago

I could be doing something wrong for sure. xD This is mostly a question, not a feature request.

But for example:

Imagine that in a web application you have two pages with their custom javascript logic. So I create a Jammit package for each page.

However, both sections use the same uploader javascript libraries. So, currently, I would have to duplicate the uploader javascript files in both packages to be able to have one javascript URL for all the code. Of course, I could just create an :uploader package and include an extra javascript URL.

But if I want to reuse other libraries or modules on different pages, I would end up having multiple javascript URLs, or duplicating the javascript files in multiple packages.

For now, I'm fine with multiple javascript URLs, but I was contemplating the possibility of what I asked.

Thanks!

jashkenas commented 13 years ago

vandrijevik's got this one right. The behavior you're describing is what asset packages are. You either have a single package for all pages with everything in it (the best choice); two packages, with the uploader JS in both; or three packages, with two HTTP requests per page.

The choice is yours.

mhayes commented 11 years ago

I realize that this ticket is quite dated, but I found some pure YAML that solves this issue nicely. You can technically declare a base package in your config/assets.yml file and then reference the base package. Here's an example of how you could do this:

javascripts:
  base: &base
    - base1.js
    - base2.js
    - base3.js
  admin:
    - *base
    - admin1.js
    - admin2.js
  user:
    - *base
    - user1.js
    - user2.js
knowtheory commented 11 years ago

If there was a way to give you github karma @mhayes i would.

Instead, have this gif:

pusheen megusta

mhayes commented 11 years ago

Sweet, that's how I roll @knowtheory!

filipewl commented 11 years ago

I was in the same situation as @favrik and @mhayes's tip was exactly what I needed. Thanks!