禁用资产指纹识别

时间:2015-02-24 16:14:42

标签: ruby-on-rails ruby ruby-on-rails-3 ruby-on-rails-4

我试图通过在config / environments / production.rb中放置以下行来禁用资产指纹识别:

  config.assets.digest = false

但是,rails并不尊重这一点,仍在使用public / assets /中的指纹编译资产:

bear-e1d6322cce5569e1c88e51d726af8f49.jpg

为什么rails忽略了这一点? 跟进问题:如果rails对指纹资产很顽固,为什么不改变html.erb文件中资产的名称,以便浏览器知道要请求的文件的正确名称?

2 个答案:

答案 0 :(得分:0)

对于低于v4的webpacker,(webpack 3), 我添加三件事:

  • 宝石'non-stupid-digest-assets'可以删除已编译的链轮资产上的指纹
  • https://www.npmjs.com/package/non-digest-webpack-plugin,以禁用由webpack编译的js路径的指纹
  • 然后我重新定义提取文本插件,而没有css文件的指纹:

    // in config/webpack/custom.js file
    const webpack = require('webpack')
    const NonDigestPlugin = require('non-digest-webpack-plugin')
    const ExtractTextPlugin = require('extract-text-webpack-plugin')
    
    module.exports = {
      devtool: 'cheap-module-source-map',
      plugins: [
        new NonDigestPlugin(),
        new ExtractTextPlugin('[name].css'),
      ]
    }
    

并在环境中导出它:

// In config/webpack/environment.js
const customConfig = require('./custom')

environment.config.merge(customConfig)
module.exports = environment

答案 1 :(得分:-2)

答案在这里: http://guides.rubyonrails.org/asset_pipeline.html#how-to-use-the-asset-pipeline

为了避免预先编译资产(和指纹识别),只需将资产置于公共/不在app / assets中