Rails config.assets.precompile setting to process all CSS and JS files in app/assets

后端 未结 8 1606
粉色の甜心
粉色の甜心 2020-11-28 06:42

I wish to precompile all the CSS and JS files in my project\'s app/assets folder. I do NOT want to precompile everything in vendor/assets or lib/assets, only th

8条回答
  •  甜味超标
    2020-11-28 07:26

    I found this in the rails code:

    @assets.precompile               = [ Proc.new{ |path| !File.extname(path).in?(['.js', '.css']) },
                                         /(?:\/|\\|\A)application\.(css|js)$/ ]
    

    Which is backed up with the rails guide:

    The default matcher for compiling files includes application.js, application.css and all non-JS/CSS files

    This default is not reset if you use +=, so you need to override it with a = instead of +=. Note that, apparently, you can pass a Proc or a regex to precompile as well as an extension. I believe, if you want to preompile only files in the top level directory, you will have to create a regex like:

    config.assets.precompile = [ /\A[^\/\\]+\.(ccs|js)$/i ]
    

提交回复
热议问题