Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does @use not work in Web Compiler Visual Studio extension?

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?

like image 759
gmeister_99 Avatar asked Dec 11 '19 22:12

gmeister_99


People also ask

How to run compilerconfig json?

You can run the compiler on all compilerconfig. json files in the solution by using the keyboard shortcut Shift+Alt+Y or by using the button on the top level Build menu.

How do I compile less to CSS in Visual Studio?

css file nested under it in Solution Explorer after being enabled on the project. By default, compilation is off and that's indicated by a watermark at the bottom right corner of any LESS file. To enable LESS compilation, simply click the watermark and it changes to indicate LESS compilation is "on". All .

What is Web compiler?

Web CompilerThe easiest and most powerful way to compile LESS, Scss, Stylus, JSX, CoffeeScript and Handlebars files directly within Visual Studio or through MSBuild.


2 Answers

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.

like image 178
Jovie Avatar answered Sep 27 '22 18:09

Jovie


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;
}
like image 27
gmeister_99 Avatar answered Sep 27 '22 17:09

gmeister_99