Grunt Sass - Output erros on console - sass

How can I set Sass to validade my scss files and output any errors on console?
I am writing this class in order to test it:
.test {
color: #ff3;
border-right: 5px solid blueee
aaaaaa
}
And when I hit Save, the console shows:
>> File "scss/app.scss" changed.
Running "sass:dist" (sass) task
Done, without errors.
But obviously as you can see, there is an error on my scss file. How can I display that on console?

Your best bet would be to try either a Sass linting tool or a CSS linting tool (or both) depending what it is you want to do.
For Sass there is grunt-scss-lint
For Css there is grunt-contrib-csslint

Related

Sass interpolation doesn't work

How do I escape variable in url? Seems like this nor this variant do not work
#include image("R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs=")
#mixin image($base64)
background: url(data:image/gif;base64,#{$base64}) //this is line N
//background: url("data:image/gif;base64,#{$base64}")
(Line N: Properties are only allowed within rules, directives, mixin
includes, or other properties.)
I tried sass 3.4.22 and 3.5.0-rc.1
The error message tells you that the background property needs to be wrapped by one of the named options.
#mixin image($base64)
background: url(data:image/gif;base64,#{$base64})
.class
#include image("R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs=")
compiles to
.class {
background: url(data:image/gif;base64,R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs=);
}
with SassMeister and Sass v3.4.21. I had to change the order of the mixin definition and its usage to make the compilation work. I don't know if this is just a compiler thing, it might work the other way around for you.

Make relative background image paths absolute with Grunt SASS?

Im using Grunt SASS
https://github.com/sindresorhus/grunt-sass
Is it possible to convert my image paths to be absolute? So if I write this:
.something {
background: url(../icon.png);
}
I would like the compiled CSS to be:
.something {
background: url(www.mysite.com/images/icon.png);
}
This can be done with grunt css url replace:
https://www.npmjs.com/package/grunt-css-url-replace
However this isnt ideal. Running an additional task will be slower and I expect this will mess up my source maps. An add on / config setting for grunt sass would be better but I cant seem to find one.

Compass - Importing mixins [duplicate]

Getting an error message when compiling my SCSS using the ruby compass gem.
run: /var/lib/gems/1.8/gems/compass-0.12.2/bin/compass compile
out: unchanged sass/partial/grid.scss
out: error sass/partial/catalog.scss (Line 5: Undefined variable: "$paragraphFont".)
out: create css/generated/partial/catalog.css
out: create css/generated/partial/base.css
out: overwrite css/generated/screen.css
My screen.scss imports partials like this:
#import "partial/base";
#import "partial/catalog";
In my base partial I have the $paragraphFont defined.
$paragraphFont: 'Lucida Sans', arial;
$regularFontSize: 14px;
And in catalog.scss I use it:
.product-view #price-block {
p {
font-weight: normal;
font-family: $paragraphFont;
....
}
}
Weird thing is that the css gets compiled just fine, and the $paragraphFont is populated correctly. So I don't know why the compiler is complaining at me about an error.
You're generating files that don't need to be generated.
screen.scss -> screen.css
base.scss -> base.css
catalog.scss -> catalog.css
The catalog file is being compiled on its own. Since it is not importing base.scss, the variables are not set. Your screen.scss file generates as you expect because it is importing all of the necessary information.
What you want to do is rename your partials to begin with an underscore to prevent them from being compiled on their own:
screen.scss -> screen.css
_base.scss (not compiled)
_catalog.scss (not compiled)
A simpler explanation that probably fits most of the users here:
You're compiling all your sass, when you only need to compile the top level file
sass is commonly modularised as follows:
toplevel.scss
include child1.scss
include child2.scss (that also uses variables from child1.sass but does not import child1.scss)
include child3.scss (that also uses variables from child1.sass but does not import child1.sass)
When compiling, you only need to compile toplevel.scss. Compiling other files on their own (eg, child2.scss) will generate errors about undefined variables.
In your gulpfile:
gulp.task('sass', function () {
gulp
.src('./static/scss/toplevel.scss') // NOT *.scss
.pipe(sass())
// Rest is just decoration
.pipe(prefixer('last 2 versions', 'ie 9'))
.pipe(gulp.dest('./static/css/dist'))
.pipe(livereload(livereloadServer));
});
In your compass log it states:
A) create css/generated/partial/catalog.css
B) create css/generated/partial/base.css
These need to be:
A) create css/generated/partial/base.css
B) create css/generated/partial/catalog.css
My guess is that your screen.scss has incorrect import statements.
I'd recommend looking into common Sass directory organizational structures. My personal favorite is The 7-1 Pattern.
The nature of it splits commonly used elements into other files, which are all imported by a main.scss to kill redundancies.
But also, firstly pay attention to #cimmanon's answer, as he more directly addresses your question.

SCSS On Sublime

I just can't get it work. I have a .scss file with some basic CSS.
Now, I have installed Ruby and I installed SASS like so - gem install sass.
What do I do to get it work on sublime?
I installed "SASS" so sublime acknowledge the .SCSS extension. I also installed SASS builder, and it actually works but in an strange way.
In addition to the compiled css file, it also adds .map file and a folder name .sass-cache.
Why Is that? How to I get rid of that? I don't need a .map file.
I also get an alert every single time the build is done. ("style.css has been compiled")
And not only that but I also get this comment at the end of my compiled CSS file:
/*# sourceMappingURL=style.css.map */
Please help, I'm lost.
Thanks in advance.
The .map file is for chrome (and maybe other browsers) to MAP your CSS that is rendered in the browser back to your actual SCSS. This is very very useful when debugging.
The scss-cache is just what it says it is a cache file that Sass uses. You can delete it but it will keep coming back every time you compile.
Once you go to production you can set Sass to not add any comments to your final css output file. You do this through a config.rb file if you are using compass.
Search on YouTube for LevelUp Tuts and Sass Compass install. Scott expanse how to get stared very well.
--sourcemap=none will disable the comment as well as the .map file creation. not so hard guys.
also, --no-cache will prevent creating the .sass-cache folder and its content.
Thanks anyway.
Try using SassBuilder for ST2. And you can config not to include comments, cache,etc with True/False.
{
"output_path": "../css",
"options": {
"cache": true,
"debug": false,
"line-comments": true,
"line-numbers": true,
"style": "nested"
}
}
For further info, click here.

False positive "undefined variable" error when compiling SCSS

Getting an error message when compiling my SCSS using the ruby compass gem.
run: /var/lib/gems/1.8/gems/compass-0.12.2/bin/compass compile
out: unchanged sass/partial/grid.scss
out: error sass/partial/catalog.scss (Line 5: Undefined variable: "$paragraphFont".)
out: create css/generated/partial/catalog.css
out: create css/generated/partial/base.css
out: overwrite css/generated/screen.css
My screen.scss imports partials like this:
#import "partial/base";
#import "partial/catalog";
In my base partial I have the $paragraphFont defined.
$paragraphFont: 'Lucida Sans', arial;
$regularFontSize: 14px;
And in catalog.scss I use it:
.product-view #price-block {
p {
font-weight: normal;
font-family: $paragraphFont;
....
}
}
Weird thing is that the css gets compiled just fine, and the $paragraphFont is populated correctly. So I don't know why the compiler is complaining at me about an error.
You're generating files that don't need to be generated.
screen.scss -> screen.css
base.scss -> base.css
catalog.scss -> catalog.css
The catalog file is being compiled on its own. Since it is not importing base.scss, the variables are not set. Your screen.scss file generates as you expect because it is importing all of the necessary information.
What you want to do is rename your partials to begin with an underscore to prevent them from being compiled on their own:
screen.scss -> screen.css
_base.scss (not compiled)
_catalog.scss (not compiled)
A simpler explanation that probably fits most of the users here:
You're compiling all your sass, when you only need to compile the top level file
sass is commonly modularised as follows:
toplevel.scss
include child1.scss
include child2.scss (that also uses variables from child1.sass but does not import child1.scss)
include child3.scss (that also uses variables from child1.sass but does not import child1.sass)
When compiling, you only need to compile toplevel.scss. Compiling other files on their own (eg, child2.scss) will generate errors about undefined variables.
In your gulpfile:
gulp.task('sass', function () {
gulp
.src('./static/scss/toplevel.scss') // NOT *.scss
.pipe(sass())
// Rest is just decoration
.pipe(prefixer('last 2 versions', 'ie 9'))
.pipe(gulp.dest('./static/css/dist'))
.pipe(livereload(livereloadServer));
});
In your compass log it states:
A) create css/generated/partial/catalog.css
B) create css/generated/partial/base.css
These need to be:
A) create css/generated/partial/base.css
B) create css/generated/partial/catalog.css
My guess is that your screen.scss has incorrect import statements.
I'd recommend looking into common Sass directory organizational structures. My personal favorite is The 7-1 Pattern.
The nature of it splits commonly used elements into other files, which are all imported by a main.scss to kill redundancies.
But also, firstly pay attention to #cimmanon's answer, as he more directly addresses your question.

Resources