Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to resolve dependency order in Rails asset pipeline?

I have a RoR app that uses lots of individual .less files to build my styles. I have one master .less file (config.less) that has variables that other files use. I can manually go through each of these child files and add @import statements, but I have quite a few, and this doesn't seem like the best way. Is there a standard way of setting a certain order if I'm using *= require_tree .?

I've tried to include require it above require_tree with

...
*= require 'less/config'
*= require_tree .

but I still get an error in a subsequent .less file complaining that it can't find a value in config

variable @base is undefined
  (in /Users/me/project/app/assets/stylesheets/less/mixins.less)
like image 665
jbnunn Avatar asked Oct 04 '22 15:10

jbnunn


1 Answers

The standard way is to not use *= require_tree . and to specify the imports/require lines individually.

From the Rails Guide

Directives are processed top to bottom, but the order in which files are included by require_tree is unspecified. You should not rely on any particular order among those. If you need to ensure some particular JavaScript ends up above some other in the concatenated file, require the prerequisite file first in the manifest. Note that the family of require directives prevents files from being included twice in the output.

like image 91
deefour Avatar answered Oct 07 '22 18:10

deefour