Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
有没有办法防止django管道每次编译react.js代码时都创建新的jsx文件?_Django_Reactjs_Django Pipeline - Fatal编程技术网

有没有办法防止django管道每次编译react.js代码时都创建新的jsx文件?

有没有办法防止django管道每次编译react.js代码时都创建新的jsx文件?,django,reactjs,django-pipeline,Django,Reactjs,Django Pipeline,我目前使用django管道安装了PyReact JSX编译器 每当我在文件上运行collectstatic时,它都会在同一文件夹中创建一个新版本,而不是覆盖react.jsx和compiled.js文件的早期版本。有没有办法停止这种情况,让程序简单地覆盖以前的版本?或者,使用django管道的最佳实践是只使用一次吗 My settings.py: PIPELINE_COMPILERS = ( 'react.utils.pipeline.JSXCompiler', 'pipeline.co

我目前使用django管道安装了PyReact JSX编译器

每当我在文件上运行collectstatic时,它都会在同一文件夹中创建一个新版本,而不是覆盖react.jsx和compiled.js文件的早期版本。有没有办法停止这种情况,让程序简单地覆盖以前的版本?或者,使用django管道的最佳实践是只使用一次吗

My settings.py:

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'

如果我没有弄错您的问题,您担心的是在运行了
collectstatic
之后,您的
STATIC\u ROOT
目录中有类似
foo.2d32ed.js
foo.4bhf45.js
foo.09d9fg.js
的文件

如果是这样,那么这就不是PyReact甚至django管道的问题;这是因为您使用的是缓存存储后端(即
STATICFILES\u存储设置)。附加到文件名后的字符串是文件内容的散列,其有效作用类似于静态文件的版本控制

原因是浏览器上的缓存破坏。使用文件名作为文件内容的函数,浏览器可以永久缓存文件,这将加快用户在后续访问中的页面加载时间

如果要禁用此行为,可以改用非缓存存储后端,如
PipelineStorage

以下是一些可能有帮助的文档: