I'm upgrading a rails app with lots of SCSS stylesheets to use the asset pipeline, and need to include some global variables and mixins for each file.
Adding several @import
directives at the top of every file isn't very DRY, so I'd like to do something like this:
# application.css
/*
*= require variables
*= require mixins
*= require_tree .
*/
This doesn't work of course, because the variables are not persisted across files. Anyone know how to achieve this?
The default manifest syntax isn't powerful enough to give you useful Sass features like shared variables, mixins, etc. Instead, you should:
Instead of using the
/*
*= require variables
*= require mixins
*= require_tree .
*/
nonsense, you should now use
@import "variables";
@import "mixins";
@import "blah"; // import each SCSS file in your project like this.
This will ensure you have full benefit of your variables and mixins throughout your project, and you are kept as DRY as Sass allows.
Simply importing the necessary file from each Scss or Sass file seems to have worked for me. For example, I have a colors.scss file that includes some constants like this:
$black: #222;
I require it in my application.css manifest along with some other files:
/*
*= require colors
*= require buttons
*/
In my buttons.css.scss file, I simply do this to avoid the error:
@import "colors";
Doesn't seem to be possible. Ended up prepending each file with @import 'includes/all';
and including everything else from includes/all.css.scss
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With