file1.scss
@function toPx($n) {
@return $n + 0px;
}
file2.scss
body {
font-size:toPx(10);
}
file3.scss
@import "file1.scss";
@import "file2.scss";
The output of file3.css contains
body {
font-size:toPx(10);
}
I can't get my toPx function to work, even if I import directly into file2.scss. If I declare toPx inside file2.scss it will work however.
I'm new to SASS so assuming I'm missing something simple here, is anyone able to tell me what?
Surprisingly Scout, the sass compiler i'm using, does not throw an error but simply renders the toPx(10) into the output CSS.
Edit
I've found this reference which seems to suggest that I will need to use the Ruby API in order to achieve a global function. Is anyone able to clarify?
http://sass-lang.com/docs/yardoc/Sass/Script/Functions.html#adding_custom_functions
In brief, @import is being replaced with more explicit @use and @forward rules. Over the next few years Sass @import will be deprecated, and then removed. You can still use CSS imports, but they won't be compiled by Sass.
Functions can be defined using @function at-rule. A function name can be any Sass identifier. It must only contain universal statements, as well as the @return at-rule which indicates the value to use result of the function call. The normal CSS functions are used for calling functions.
You can not "attach" a SASS/SCSS file to an HTML document. SASS/SCSS is a CSS preprocessor that runs on the server and compiles to CSS code that your browser understands.
I stumbled upon a hack answer, that makes me think it's probably a Scout bug.
I altered file3.scss to this
@import "file1.scss";
@import "file2.scss";
body {
font-size:toPx(10);
}
After compiling that, it worked as intended. Next I changed my files back to how I described in the question and now all my calls for toPx work in any file.
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