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 optional @imports #779
Comments
👍 |
In general, we're not planning on adding anything to the current I'm not sure this is something that's worth putting in the core Sass language. It seems like a reasonable use-case for defining a custom importer, though. #739 would also go part of the way towards obviating the need for this. |
@imathis Can you restructure your theme folder so that you could do this with the Sass globbing plugin?
Just a thought. |
I emailed a reply but I don't see it here: @nex3 I'd like to discuss this with you. I don't see how optional imports are wasted effort with future development plans -- would like to understand why you think this is true. This use case is an interesting one and I'd like to think about it more before discarding it out of hand. |
I don't think it's worthwhile to add additional syntax to a construct we're planning on deprecating anyway. |
What about conditional loading within control directives and/or mixins? The use case described by @imathis could also be implemented like this : $partial : path/to/partial;
@if import-exists($partial) {
@import $partial;
} Not only does it solve the same problem a different way, but it would also allow one to do stuff like this : @if not function-exists(str-replace) {
@import '_str-replace';
} @if $sassversion > 3.2 {
@import '_new-sass';
} @else {
@import '_old-sass';
} $partial : path/to/partial;
@if import-exists($partial) {
@import $partial;
} I posted this as a separate issue, since my use case is a lot broader and the syntax is very different. |
I don't think this is going to make it into the new |
👍 for see optional flag in Look a very good use case https://github.com/Semantic-Org/Semantic-UI/blob/master/src/theme.less#L36 |
what is the status of this... is there a way to include a partial only if it exists? |
He is a she. You could have |
Optional @import is really important |
Any update on this? I've literally been waiting for optional imports to be implemented for >2 years now... |
Until it gets implemented, I have come across two potential workarounds which may be helpful depending on the use case so I'll post them: 1 - Internal
|
I would really love this feature, seems essential long term, just a matter of when. |
I believe it would be helpful to framework design and stylesheet modularity if there were a way to declare an
@import
which would fail gracefully if a file was not found.Jumpt to the TL;DR
Syntax
To make it's behavior obvious this could be a flag
!optional
borrowing from the style of!default
and!important
. It might look like this:Use case
In Octopress I'm trying to make it easy for people to easily install themes and plugins (with their Sass assets) and I want it to be easy for users to customize these theme and plugin stylesheets. At the same time I want it to be possible for users to enjoy Octopress without installing any themes or plugins. As a result I have come up with this method for managing Sass.
Let's look at an Octopress stylesheet directory
The root stylesheets
site.scss
uses optional imports and globbing to automatically import stylesheets from a theme or plugins.Here
!optional
imports would allow me to create a zero configuration install experience for end users. Users can install themes or plugins (or not) and they will automatically be imported. Also if I can reasonably expect them not to have any reason to change thesite.scss
file, making it easier for me to make changes to that file if needed.Additionally if I wanted to allow users to easily override theme or plugin settings, I could change the
site.scss
like this:This will allow a user to create a specific file to set default settings for a theme or plugin before it is imported. Without optional imports, a user must make changes to core files.
TL;DR
If imports can respect an
!optional
flag, frameworks like Octopress can create a framework which allows users to install new stylesheets without having to manage imports. Essentially this would allow zero-configuration installation for Sass stylesheets.The text was updated successfully, but these errors were encountered: