1

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)

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
luc2
  • 547
  • 1
  • 4
  • 11

1 Answers1

1

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)
jazgot
  • 1,943
  • 14
  • 25
  • i wrote that in "models.py". it works, but is it appropriate to write that in "models.py" ? – luc2 Jun 01 '15 at 13:17
  • It works, but it's so ugly. Why doesn't pipeline offer a way to not publish the source files along the compiled version? :( – Mickaël Aug 29 '15 at 00:19
  • I don't think it's ugly. It's just hooking to an event dispatched by library. Replacing some core protected function or mocking whole class would be ugly ;) – jazgot Aug 30 '15 at 06:51