Search code examples
djangodjango-pipelinecollectstatic

Automatically remove source files after collectstatic with django-pipeline


With django-pipeline, is it possible to automatically remove source files after collectstatic ?

for example :

PIPELINE_JS = {
    'stats': {
        'source_filenames': (
          'js/jquery.js',
          'js/d3.js',
          'js/application.js',
        ),
        'output_filename': 'js/stats.js',
    }
}

collectstatic :

$ python manage.py collectstatic
$ ls static/js
jquery.js
d3.js
application.js
stats.js

(i don't want jquery.js, d3.js, application.js)


Solution

  • Django-pipeline sends signals whenever it compiles package, you can read more about this in docs, and about signals in general here. You can hook this signal like this:

    from pipeline.signals import js_compressed
    
    def clear_files(sender, **kwargs):
        print kwargs
        if 'package' in kwargs:
            print kwargs['package'].sources
            # here remove unwanted files
    
    js_compressed.connect(clear_files)