Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow a bundle to not have an output #164

Closed
sontek opened this issue Jul 23, 2012 · 4 comments
Closed

Allow a bundle to not have an output #164

sontek opened this issue Jul 23, 2012 · 4 comments

Comments

@sontek
Copy link
Contributor

sontek commented Jul 23, 2012

We should have the ability to define a bundle, without an output, so that it can be included in the templates which will declare an output.

For instance:

{% assets filters="cssmin", output="gen/packed.css", "boostrap.css", "styles.css", "sass" %}

sass in this case would be a bundle that you would declare:
sass = Bundle('static/sass/*.sass', filters='sass', debug=False)

No reason to require it to have an output since it'll be included with the tag.

@miracle2k
Copy link
Owner

So, I think your example should work fine with environment.debug=False. It'll only be a problem in debug mode, because now it tries to render the urls for bootstrap.css, styles.css, and then tries to build the sass bundle, and now needs an output file.

It can't easily use gen/packed.css, because of course, your bundle may as well look like this:

{% assets filters="cssmin", output="gen/packed.css", "sass1", "boostrap.css", "styles.css", "sass2" %}

And the only way to resolve this while maintaining order would be to write everything into a single file, i.e. the equivalent of environment.debug=''merge".

So if in debug mode you want everything in a single file, you should be fine by just using debug='merge' (also possible on a bundle-level). If you want separate urls for each css file, you need to provide an output file for the sass bundle.

I'm not sure if there is anything that can be changed here.

@sontek
Copy link
Contributor Author

sontek commented Aug 8, 2012

I'm currently getting this bug with the pyramid extension I developed:
https://github.com/sontek/pyramid_webassets/blob/master/pyramid_webassets/__init__.py#L121

here are my bundles:
common_sass_bundle = Bundle(
'src/common/sass/*.sass'
, filters='compass'
, debug=False
)

common_less_bundle = Bundle(
    'src/common/less/*.less'
    , filters='less'
    , debug=False
)

common_style_bundle = Bundle(
    common_sass_bundle
    , common_less_bundle
    , filters='cssmin'
    , output='generated/common.css'
)

config.add_webasset('common_style', common_style_bundle)

You see, I actually define an output for the common_style_bundle but when I actually use it, I generate a new output anyways:

% for url in webassets(request, 'css/bootstrap.css', 'common_style', \
'css/bootstrap-responsive.css', output='css/generated.css', filters='cssmin'):
  <link href="${url}" rel="stylesheet">
% endfor

but I get the error:

BuildError: No output target found for <Bundle output=None, filters=[<webassets.filter.compass.CompassFilter object at 0x32cd310>], contents=('src/common/sass/*.sass',)>

but both of the toplevel bundles I defined have outputs, the one its erroring on doesn't have one on its own but that should be ok?

@miracle2k
Copy link
Owner

You want the output from both common_less_bundle and common_sass_bundle to appear in a single file, generated/common.css.

Someone else might want a separate output file for the less bundle, and a separate output file for the sass bundle.

Right now, webassets expects everyone to be in group two. This is the way it works; if webassets encounters debug=False for the first time, it decides that this bundle is the first one that needs to be be built (as opposed to outputting the source urls), and looks for an output file. If it doesn't find one, it fails.

There is however a simple way for you to get the desired behavior: You can add debug="merge" to common_style_bundle. Then, when traversing the bundle structure, common_style_bundle will be the first one that needs to be built, and since it has an output file, everything works out fine.

This is the correct fix for you. There might be a way for webassets to be smart and to the right thing for you here - I'll need to look into it. But what it would do is simply silently treat common_style_bundle to be in merge mode, because that's is essentially what you want to happen here - for common_sass_bundle and common_less_bundle to be merged together into one file, without the cssmin filter running. So right now, I believe this should be a suitable solution for your problem.

FWIW, debug=False is no longer required in the development version. Usage of filters like less or sass will automatically cause a Bundle to behave like if debug=False were specified.

There is also a related ticket, #168, which would provide a mode where each of the less and sass source files would be compiled into their own output file, with no merging going on, thus letting you see clearly during development in the browser what particular source file a CSS file goes back to.

@sontek
Copy link
Contributor Author

sontek commented Aug 19, 2012

It would be nice if it was smart enough to figure it out but this is enough information to work around it :)

@sontek sontek closed this as completed Aug 19, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants