I'm running Visual Studio 2019 (16.3.9) using the Web Compiler extension (1.12.394) to compile scss files.
Here is a simple case that works. I have a file - test.scss:
$color: blue;
.button {
background-color: $color;
}
This gets compiled to this:
.button {
background-color: blue;
}
But if I try and do something like what is outlined here - https://sass-lang.com/documentation/at-rules/use#configuring-modules - it doesn't seem to work. I create another file - _base.scss:
$color: red !default;
.button {
background-color: $color;
}
Then I change my test.scss file to this:
#use 'base' with (
$color: blue
);
I expected that the compiled output would be the same as the original example:
.button {
background-color: blue;
}
But this is what I get:
#use 'base' with (
$color: blue
);
My guess is that the compiler is not happy with the #use rule, but I don't see any errors. _base.scss & test.scss are in the same directory. I'm only new to Sass, but surely this should be possible?
This is filed as an issue on Web Compiler on GitHub:
#use does not work
The response is:
#use its currently supported only by dart-sass and other platforms use
#import for now so this is not a Web Compiler issue
I am also new to Sass, and I can't figure out how to tell what version of Sass is supported in Web Compiler. (Edit: Just found SO question Which version of SASS is my WebCompiler extension using?)
Frustrating, because I am struggling with preventing duplicated CSS from #imports and it seems like #use is the answer.
As mentioned, I'm new to Sass so was jumping straight in with the latest features. My first hunch, as mentioned by #Bauke, is that the current version of Web Compiler doesn't support #use (and other new features of Sass).
Based on this, I opted for a workaround with currently supported features that achieves the same result.
_base.scss:
$color: red !default;
.button {
background-color: $color;
}
test.scss:
$color: blue;
#import 'base';
Compiled output:
.button {
background-color: blue;
}
Related
Am trying to use SASS in my project. I wrote a SCSS and then converted that to CSS.
The SCSS I created is ,
$primaryColor: #D92231;
body {
$primaryColor: #ccc;
background: $primaryColor;
}
p {
background-color: $primaryColor;
}
ui-btn {
background-color: $primary-color;
}
Converted that SCSS to CSS by the command,
sass-convert style.css style.scss
Finally I got the CSS generated. Generated CSS is ,
$primaryColor: #D92231
body
background: $primaryColor
p
color: $primaryColor
ui-btn
background-color: $primary-color
I linked this to my html page but no effect. Where am I going wrong ???
The generated CSS isn't actually CSS as sass-convert doesn't actually convert sass to css.
It converts CSS to SASS or SCSS dependant on what you want.
To convert the SCSS to SASS you will need to run the below script. You will need SASS installed.
sass input.scss output.css
Alternatively, you can run a script to have Ruby watch the SCSS file and update on every save.
Like so:
sass --watch input.scss:output.css
Read more here: Documentation
Try your Sass at sassmeister.com and you'll see that primary-color variable is not defined. I believe your code never gets compiled because of that error. See : Sassmeister output in Github Gist
I don't really find an answer on liferay's blogs and google - so i hope anyone here can help me.
I'm trying to get started with sass in a custom theme i am building in liferay 6.2.
As i understand it, the approach would be this:
create an empty theme, (using maven,) based off _styled
this gives me a file layout like this:
<theme>
+-src
+-main
+-webapp
+-css
+- ... here i'll put any css overwrites
develop sass stylesheets, link to main.css
<theme>
+-src
+-main
+-webapp
+-css
+-main.css
+-custom.scss
main.css initially looks like this:
#import url(custom.css);
/* other css import here */
custom.scss would contain some SASS content:
$color: #f00;
body {
color: $color;
}
Now my question: How do I link both CSS and SASS together correctly? How does the #import statement in main.css have to be defined?
I tried #import url(custom.scss); but this won't give me the desired results. Likewise, #import url(custom.css); won't do it either.
I found the solution. Key is to understand that Liferay does not use the file extension *.scss on a theme's stylesheets. Just dropping my SASS code into a *.css file did the job!
Found the solution here.
My directory layout:
<theme>
+-src
+-main
+-webapp
+-css
+-main.css
+-custom.css
main.css looks like:
#import url(custom.css);
/* other css import here */
and custom.css like this:
$color: #f00;
body {
color: $color;
}
And the result is (in custom.css, after reloading on the web browser):
body {
color: #f00;
}
Hooray!
Yes, if you are working in Liferay 6.2 file extension should be .css, but if you are working in Liferay 7/DXP it should be .scss.
I am trying to use the following include in my style.scss file:
#include box-shadow(red 2px 2px 10px);
However i get a an error of:
WARNING: box-shadow is deprecated and will be removed in the next
major version release
I've tried to google this, but i am not sure what i use instead, is there another mixin i can manually make or use? I looked on the Bourbon website in their docs but all i found was:
Deprecation Warning: The box-shadow mixin has been deprecated. Use the
official spec.
Here is the discussion within Bourbon
Box-shadow mixin should be deprecated based on current implementation of the property in browsers.
so you should use:
box-shadow: red 2px 2px 10px;
instead of:
#include box-shadow(red 2px 2px 10px);
For example:
app.scss
#import url('orange.css');
#import 'navel.scss';
orange.css
.orange {
color: orange;
}
navel.scss
.navel {
#extend .orange;
}
In SASS if you add
#import "test.css";
or
#import url("test.css");
it is compiled to pure css #import directive. Because the file has a .css extension, the SASS preprocessor thinks that this is pure CSS and the code inside is not involved in the SASS language operations. In your example, if you try to extend .orange you will get:
The selector ".orange" was not found.
Shortly: the extending is possible only if you use SASS files.
#extend is not possible by importing a CSS file. You have to
convert your css into an SCSS partial (or file)
#import this partial
#extend CSS classes
The downside to this is you would be left with duplication. Supposed this import is a 7000 line long CSS file (like bootstrap), then you are going to be in trouble
I started to importing shared things like variables and mixins in one place - css manifest file. Now I'm importing some Compass mixins using direct path to the files.
My question is if using #import 'compass' injects the whole framework into application.css or is it done by looking by references in sass files and then importing only needed mixins?
I don't want to include everything.
According to the docs #import 'compass' will import CSS3, Typography and Utilities modules. These modules won't inject anything into your output CSS, they contain only mixins.
By limiting import to a specific module or submodule (i.e. #import 'compass/css3/image') you will reduce the time required to compile your SASS files into CSS.
For example, lets create two files.
// all.scss
#import "compass";
.candy {
#include background(linear-gradient(top left, #333, #0c0));
}
// module.scss
#import "compass/css3/images";
.candy {
#include background(linear-gradient(top left, #333, #0c0));
}
If we compile them (compass compile sass/FILENAME.scss), result CSS will be identical:
.candy {
background: -webkit-gradient(linear, 0% 0%, 100% 100%, color-stop(0%, #333333), color-stop(100%, #00cc00));
background: -webkit-linear-gradient(top left, #333333, #00cc00);
background: -moz-linear-gradient(top left, #333333, #00cc00);
background: -o-linear-gradient(top left, #333333, #00cc00);
background: linear-gradient(top left, #333333, #00cc00);
}
Now lets add --time argument to the compilation command and compare the results. For my machine, it took 1.516 s to compile all.css vs only 0.108 s for module.css.