New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow @import within @if #451
Comments
3.1.7 works fine, change came in 3.1.8. It's not documented in the changelog. |
Given this file: @if true {
@import "foo";
} When I compile it using Sass 3.1.7 I get the following error:
There was a bug where an It was never intended that |
Maybe have a flag in the config file to enable/disable this restriction? On Wednesday, July 18, 2012, Chris Eppstein wrote:
|
It's not a feature that ever existed. Users who do this would encounter many strange bugs. If you like, please open a new issue and we can discuss adding this feature in a future release. |
Well I was using this for at least 9 months and didn't encounter anything Thanks, I will open a ticket. On Wednesday, July 18, 2012, Chris Eppstein wrote:
|
I have to add: Just checked the compiled css files. Turns out all the fonts had been included for all languages. Such a huge bug in my code :)) |
node-sass just fixed this: sass/sass#451 meaning @import can no longer go inside @if. This commit moves the @import outside of the @if.
Same error is still resuming. So what is the best way for resolve this? |
It already doesn't work in last version of libsass 3.3.6 but it works in 3.3.2 |
I know this issue is closed and a proper solution is being worked on by the Sass team, but this issue is the first result when Googling for I've been looking for a solution for quite a while now and I found somewhat of a temporary (little bit nasty) solution. Warning: it's not the most elegant solution and it does create extra styling. This technique will only let you conditionally load files, so it won't allow variables inside the $file: true; // set to false if you don't want to load the file
%loadFile {
@import "file/you/want/to/conditionally/load";
}
html {
@if $file == true {
@extend %loadFile;
}
} The The reason I need this is because I'm including Select2 in a library I'm working on and I really want to be able to conditionally load files depending on variables. So if I'm using this in a project I can decide per project if I need select2 (and all other molecules) or not. Since the select2 SCSS files have Again, not the most elegant solution and only useful if you want to conditionally load files. If you need theming I'm afraid you'll have to wait. |
@robinpoort You can try mixins instead, as described in #739 (comment), #739 (comment) and #739 (comment) |
@ArmorDarks yep that works for theming and other files that are related to your own project. Not the thing I was trying to solve though. As I stated I want to be able to conditionally load 3rd party libraries using only variables. As you can see in the the select2 repo they're using There's even So for the people who need theming (or only have to deal with their own files) definitely use Cheers! |
@robinpoort I see. Another solution would be to use Then you could do something like this: // `mixin@` says, that this import should be imported as a mixin
@import 'mixin@path/to/3rdparty/some-module';
@if $something {
// Now, that module available to use as a mixin with module's filename
@include some-module();
} Since it matters only to your own project, using custom importer is quite okay. But it isn't for frameworks, though. |
@ArmorDarks Thanks! I agree my method isn't a very good solution for large frameworks with the extra CSS. Works for me now, might go and play around with your solution once it's out of the experimental phase! |
In one of the recent versions, the ability to have
@import
within@if
has been deprecated. I looked through the changelog. Couldn't find anything mentioning that change,Anyway,
@import
within@if
gives the dev a lot of flexibility.Example:
Explanation:
Simply, it imports some arabic fonts only in persian.css.
I actually use this feature in almost all of my designs, since they are all multi-language, multi-directional designs. Deprecating it simply breaks all of those styles.
I will be downgrading to an earlier version for now.
The text was updated successfully, but these errors were encountered: