【问题标题】:Magento2 not auto generate static filesMagento2 不会自动生成静态文件
【发布时间】:2016-09-30 19:01:00
【问题描述】:

我在pub/static 文件夹中自动生成静态文件时遇到了一些问题

使用magento setup:static-content:deploy 后,如果我删除了一些由部署生成的静态文件,例如 css,并且我指向如下 URL:

<my_domain>/pub/static/frontend/<my_module>/<my_theme>/en_US/css/theme.css

magento2 不再自动生成它了...我需要一些提示!

  • 我处于开发者模式
  • 我已清除 var/cachevar/view_preprocessed 文件夹
  • 我已经刷新了 magento2 缓存
  • 我设置了服务器端少编译
  • 如果我使用 magento setup:static-content:deploy 一切正常!
  • 在 windows 和 unix 环境下也有同样的问题

【问题讨论】:

    标签: deployment magento2 static-content


    【解决方案1】:

    请检查您的 pub/static 文件夹。

    .htaccess 文件应该用于自动生成静态内容

    默认pub/static/.htaccess如下:

    <IfModule mod_php5.c>
    php_flag engine 0
    </IfModule>
    
    <IfModule mod_php7.c>
    php_flag engine 0
    </IfModule>
    
    # To avoid situation when web server automatically adds extension to path
    Options -MultiViews
    
    <IfModule mod_rewrite.c>
        RewriteEngine On
    
        # Remove signature of the static files that is used to overcome the browser cache
        RewriteRule ^version.+?/(.+)$ $1 [L]
    
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-l
    
        RewriteRule .* ../static.php?resource=$0 [L]
    </IfModule>
    
    ############################################
    ## setting MIME types
    
    # JavaScript
    AddType application/javascript js jsonp
    AddType application/json json
    
    # CSS
    AddType text/css css
    
    # Images and icons
    AddType image/x-icon ico
    AddType image/gif gif
    AddType image/png png
    AddType image/jpeg jpg
    AddType image/jpeg jpeg
    
    # SVG
    AddType image/svg+xml svg
    
    # Fonts
    AddType application/vnd.ms-fontobject eot
    AddType application/x-font-ttf ttf
    AddType application/x-font-otf otf
    AddType application/x-font-woff woff
    AddType application/font-woff2 woff2
    
    # Flash
    AddType application/x-shockwave-flash swf
    
    # Archives and exports
    AddType application/zip gzip
    AddType application/x-gzip gz gzip
    AddType application/x-bzip2 bz2
    AddType text/csv csv
    AddType application/xml xml
    
    <IfModule mod_headers.c>
    
        <FilesMatch .*\.(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2)$>
            Header append Cache-Control public
        </FilesMatch>
    
        <FilesMatch .*\.(zip|gz|gzip|bz2|csv|xml)$>
            Header append Cache-Control no-store
        </FilesMatch>
    
    </IfModule>
    
    <IfModule mod_expires.c>
    
    ############################################
    ## Add default Expires header
    ## http://developer.yahoo.com/performance/rules.html#expires
    
        ExpiresActive On
    
        # Data
        <FilesMatch \.(zip|gz|gzip|bz2|csv|xml)$>
            ExpiresDefault "access plus 0 seconds"
        </FilesMatch>
        ExpiresByType text/xml "access plus 0 seconds"
        ExpiresByType text/csv "access plus 0 seconds"
        ExpiresByType application/json "access plus 0 seconds"
        ExpiresByType application/zip "access plus 0 seconds"
        ExpiresByType application/x-gzip "access plus 0 seconds"
        ExpiresByType application/x-bzip2 "access plus 0 seconds"
    
        # CSS, JavaScript
        <FilesMatch \.(css|js)$>
            ExpiresDefault "access plus 1 year"
        </FilesMatch>
        ExpiresByType text/css "access plus 1 year"
        ExpiresByType application/javascript "access plus 1 year"
    
        # Favicon, images, flash
        <FilesMatch \.(ico|gif|png|jpg|jpeg|swf|svg)$>
            ExpiresDefault "access plus 1 year"
        </FilesMatch>
        ExpiresByType image/gif "access plus 1 year"
        ExpiresByType image/png "access plus 1 year"
        ExpiresByType image/jpg "access plus 1 year"
        ExpiresByType image/jpeg "access plus 1 year"
        ExpiresByType image/svg+xml "access plus 1 year"
    
      # Fonts
        <FilesMatch \.(eot|ttf|otf|svg|woff|woff2)$>
            ExpiresDefault "access plus 1 year"
        </FilesMatch>
        ExpiresByType application/vnd.ms-fontobject "access plus 1 year"
        ExpiresByType application/x-font-ttf "access plus 1 year"
        ExpiresByType application/x-font-otf "access plus 1 year"
        ExpiresByType application/x-font-woff "access plus 1 year"
        ExpiresByType application/font-woff2 "access plus 1 year"
    
    </IfModule>
    

    【讨论】:

    • @iTorso 这个 .htaccess 将丢失的文件传递给 pub/static.php 并部署单个文件
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-20
    • 2023-03-06
    • 2022-07-11
    • 1970-01-01
    • 2021-04-05
    • 1970-01-01
    相关资源
    最近更新 更多