Is there a way to prevent django pipeline creation from creating new jsx files every time it compiles react .js code?

I currently have the PyReact JSX compiler installed using the django pipeline.

Whenever I run collectstatic on my files, instead of overwriting the previous version of my reactive .jsx and compiled .js files, it creates a new version in the same folder. Is there a way to stop this and the program will just overwrite the previous version? Or, is it best to use the django pipeline to only use it once?

My .py settings:

PIPELINE_COMPILERS = (
  'react.utils.pipeline.JSXCompiler',
  'pipeline.compilers.less.LessCompiler',
)

PIPELINE_JS = {
    'bootstrap': {
        'source_filenames': (
          'twitter_bootstrap/js/transition.js',
          'twitter_bootstrap/js/modal.js',
          'twitter_bootstrap/js/dropdown.js',
          'twitter_bootstrap/js/scrollspy.js',
          'twitter_bootstrap/js/tab.js',
          'twitter_bootstrap/js/tooltip.js',
          'twitter_bootstrap/js/popover.js',
          'twitter_bootstrap/js/alert.js',
          'twitter_bootstrap/js/button.js',
          'twitter_bootstrap/js/collapse.js',
          'twitter_bootstrap/js/carousel.js',
          'twitter_bootstrap/js/affix.js',
        ),
        'output_filename': 'js/b.js',
    },
    'clubs': {
        'source_filenames': (
          'js/clubs.jsx',
        ),
        'output_filename': 'js/clubs.js',
    },
    'react': {
        'source_filenames': (
            'react/js/react.min.js',),
        'output_filename': 'js/r.js',
    },
    'jquery': {
        'source_filenames': (
            'js/jquery.js',
        ),
        'output_filename': 'js/jq.js',
    },
}

STATIC_ROOT = BASE_DIR + '/static/'

STATIC_URL = '/static/'

STATICFILES_STORAGE = 'pipeline.storage.PipelineCachedStorage'

      

+3


source to share


1 answer


If I understand your question correctly, your concern is that after the start collectstatic

you have a file type foo.2d32ed.js

, foo.4bhf45.js

, foo.09d9fg.js

in the catalog STATIC_ROOT

.

If so, then this is not a problem with PyReact or even the django pipeline; this is because you are using a cached storage server (i.e. your parameter STATICFILES_STORAGE

). The string appended to your filename is a hash of the file's content that effectively acts as versioning your static files.

This is caused by a cache overflow in browsers. With the filenames as functions of the file content, the browser can cache the file forever, which will speed up page loading for your users on subsequent visits.



If you want to disable this behavior, you can use a non-caching backend instead, eg PipelineStorage

.

Here are some docs that might help:

+5


source







All Articles