jazzband / django-pipeline

Pipeline is an asset packaging library for Django.
https://django-pipeline.readthedocs.io/
MIT License
1.52k stars 371 forks source link

add option to NOT Copy files defined in a pipeline #343

Open ilovett opened 10 years ago

ilovett commented 10 years ago

I'm not sure where this request should go... either with django-pipeline or django-storages or even something to do with collectstatic

It would be great to have an option to abort uploading / copying files which build a compressed asset... Or delete them after they have been post-processed... In my case, I have a compressed js file and would like to only upload the compressed version to production / S3, and not all the other files that were used to build it.

PIPELINE_JS = {
    'example': {
        'source_filenames': (
            'js/app.js',
            'js/helpers.js',
            'js/router.js',
            'js/templates/*.handlebars',
            'js/templates/**/*.handlebars',
            'js/controllers/*.js',
            'js/views/*.js',
            'js/models/*.js',
            'js/routes/*.js',
        ),
        'output_filename': 'js/example.compressed.js',
    }
}

After collectstatic all of those files exist in staticfiles or on s3 ... would be cool to have an to remove either all of those or some sort of wildcard path to ignore uploading... For example:

PIPELINE_JS = {
    'example': {
        'post_delete': ['js/**'],   // this will compare against paths provided in source_filenames and all matches will be provided to some sort of post hook to delete
        'source_filenames': (
            'libs/prototypes.js',
            'libs/jquery-2.0.3.js' if not PROD else 'libs/jquery-2.0.3.min.js',
            'libs/jquery.helpers.js',
            'libs/jquery.easing.1.3.js',
            'libs/handlebars-v1.1.2.js',
            'js/app.js',
            'js/helpers.js',
            'js/router.js',
            'js/templates/*.handlebars',
            'js/templates/**/*.handlebars',
            'js/controllers/*.js',
            'js/views/*.js',
            'js/models/*.js',
            'js/routes/*.js',
        ),
        'output_filename': 'js/example.compressed.js',
    }
}
ilovett commented 10 years ago

With the help of @kevin-brown who pointed me using custom Finders... looking at the code I saw ignore_patterns which looked like exactly what I needed. I ran into problems though using more than 1 finder... perhaps they are overriding each other.

STATICFILES_FINDERS = (
    'pipeline.finders.FileSystemFinder',
    'pipeline.finders.AppDirectoriesFinder',
)

This setup for example, you can see *.cssis in ignore_patterns of AppDirectoriesFinder

class AppDirectoriesFinder(PatternFilterMixin, AppDirectoriesFinder):
    """
    Like AppDirectoriesFinder, but doesn't return any additional ignored
    patterns.

    This allows us to concentrate/compress our components without dragging
    the raw versions in via collectstatic.
    """
    ignore_patterns = [
        '*.js',
        '*.css',
        '*.less',
        '*.scss',
    ]

But '*.css' is not included in ignore_patterns of FileSystemFinder....

When I performed collectstatic, the css files were getting through, but js files werent... *.js is ignored in both Finders.

So then I decided to make my own custom finder. I assumed I could customize even more here, for example, you might want all js/*.js ignored, but vendor/*.js to get through... It would be great if ignore_patterns supported this -- which could be tied into my proposal in my first post.

ErikEvenson commented 10 years ago

+1 -- this would be very nice. I use django-pipeline to compile and compress my app which is written primarily in coffeescript. django-pipeline supports this great, but I end up with *.coffee files on my static file server. I will probably do what @ilovett is suggesting, but it would be nice to just be able to specify glob patterns to avoid pushing these files to the server.

SmileyChris commented 10 years ago

Here's a module that provides more clever pipeline finders: https://gist.github.com/SmileyChris/78d1922789b316ac1c84

Apart from the cached_property bits, it would be easy to drop this into core code. I'll probably get around to a proper pull request at some time in the distant future if noone else does.

schmitch commented 10 years ago

on my side the clever filters won't work.. I still have *.scss files