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

[question] Is it possible to get minification without having to bundle files together? #732

Open
nemesifier opened this issue Nov 2, 2020 · 5 comments
Labels

Comments

@nemesifier
Copy link

Is it possible to get minification without having to bundle files together?

I'm looking for something like the django ManifestStaticFilesStorage only with minification added, so I started looking if django-pipeline provides this, but it seems it doesn't.

Anyone can help me clarifying this doubt?

@unitedsoftwork
Copy link

@nemesisdesign have you found a solution to this? I am trying to do the same thing.

@nemesifier
Copy link
Author

@bigbob556677 I found two possible solutions using other packages:

But I'm still using pipeline for minifying the HTML.

I think it would be better to have this feature shipped in pipeline instead of having to install other packages.

If the maintainers think this could be a good feature to add, let me know.

@Pyvonix
Copy link

Pyvonix commented Jan 23, 2021

Hi @nemesisdesign,

Can you be more precise when you say "having to bundle files together"? What behavior did you want?

@nemesifier
Copy link
Author

Hi @nemesisdesign,

Can you be more precise when you say "having to bundle files together"? What behavior did you want?

This is the feature I'm looking for: https://github.com/armandtvz/django-compress-staticfiles/blob/master/compress_staticfiles/storage.py

A storage class based on django ManifestFilesMixin, which also takes care of minification.

@Pyvonix
Copy link

Pyvonix commented Jan 23, 2021

The Django documentation say:

Use this mixin with a custom storage to append the MD5 hash of the file’s content to the filename as ManifestStaticFilesStorage does.

They don't say anything about ManifestStaticFilesStorage natively care about minification.
Note: PipelineManifestStorage is already available on pipeline/storage.py

If you really want to use ManifestFilesMixin, you can create a custom Pipeline class-based like documented on storages:

from django.contrib.staticfiles.storage import ManifestFilesMixin
from pipeline.storage import PipelineMixin

class YourPipelineManifestFilesMixin(PipelineMixin, ManifestFilesMixin):
    pass

Then, you can use it by set in settings.py from its custom location: STATICFILES_STORAGE = 'your.app.YourPipelineManifestFilesMixin'

Tell me if I'm wrong, but what you don't really want should be a compressor based on rjsmin like django-compress-staticfiles do?

Understand the actual behavior:
The problem with the actual behavior of django-pipeline, the library "append" each file in 'source_filenames' in your STYLESHEETS and JAVASCRIPT and compress (if enable) the result.

What you should do:
If you just want to compress your files without bundle them, you should create one entry for each file and use one compressor.

Example:

PIPELINE = {
    'PIPELINE_ENABLED': True,
    # CSS config
    'CSS_COMPRESSOR': 'pipeline.compressors.csshtmljsminify.CssHtmlJsMinifyCompressor',
    'STYLESHEETS': {
        'style1': {
            'source_filenames': (
                'css/style1.css',
            ),
            'output_filename': 'css/style1.min.css',
            'extra_context': {
                'media': 'screen,projection',
            }
        },
        'style2': {
            'source_filenames': (
                'css/style2.css',
            ),
            'output_filename': 'css/style2.min.css',
            'extra_context': {
                'media': 'screen,projection',
            }
        },
    },
    # JS config
    'JS_COMPRESSOR' : 'pipeline.compressors.csshtmljsminify.CssHtmlJsMinifyCompressor',
    'JAVASCRIPT': {
        'js1': {
             'source_filenames': (
                'js/js1.js',
            ),
            'output_filename': 'css/js1.min.css',
        },
        'js2': {
             'source_filenames': (
                'js/js2.js',
            ),
            'output_filename': 'css/js2.min.css',
        },
    }
}

Explanation:

  • css/style1.css will be compressed with CssHtmlJsMinifyCompressor under css/style1.min.css
  • css/style2.css will be compressed with CssHtmlJsMinifyCompressor under css/style2.min.css
  • js/js1.css will be compressed with CssHtmlJsMinifyCompressor under js/js1.min.css
  • js/js2.css will be compressed with CssHtmlJsMinifyCompressor under js/js2.min.css

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants