Is there anyway to import a regular CSS file with Sass's @import
command? While I'm not using all of the SCSS syntax from sass, I do still enjoy it's combining/compressing features, and would like to be able to use it without renaming all of my files to *.scss
Sass has two syntaxes! The SCSS syntax ( . scss ) is used most commonly. It's a superset of CSS, which means all valid CSS is also valid SCSS.
The @import rule allows you to import a style sheet into another style sheet. The @import rule must be at the top of the document (but after any @charset declaration). The @import rule also supports media queries, so you can allow the import to be media-dependent.
After having the same issue, I got confused with all the answers here and the comments over the repository of sass in github.
I just want to point out that as December 2014, this issue has been resolved. It is now possible to import css
files directly into your sass file. The following PR in github solves the issue.
The syntax is the same as now - @import "your/path/to/the/file"
, without an extension after the file name. This will import your file directly. If you append *.css
at the end, it will translate into the css
rule @import url(...)
.
In case you are using some of the "fancy" new module bundlers such as webpack, you will probably need to use use ~
in the beginning of the path. So, if you want to import the following path node_modules/bootstrap/src/core.scss
you would write something like @import "~bootstrap/src/core"
.
NOTE:
It appears this isn't working for everybody. If your interpreter is based on libsass
it should be working fine (checkout this). I've tested using @import
on node-sass and it's working fine. Unfortunately this works and doesn't work on some ruby instances.
This was implemented and merged starting from version 3.2
(pull #754 merged on 2 Jan 2015 for libsass
, issues originaly were defined here: sass
#193 #556, libsass
#318).
To cut the long story short, the syntax in next:
@import "path/to/file";
@import "path/to/file.css";
And it is damn good: this syntax is elegant and laconic, plus backward compatible! It works excellently with libsass
and node-sass
.
__
To avoid further speculations in comments, writing this explicitly: Ruby based Sass still has this feature unimplemented after 7 years of discussions. By the time of writing this answer, it's promised that in 4.0 there will be a simple way to accomplish this, probably with the help of @use
. It seems there will be an implementation very soon, the new "planned" "Proposal Accepted" tag was assigned for the issue #556 and the new @use
feature.
UPD: on 26 October 2020 lib-sass was deprecated, therefore issue #556 was immediately closed.
__
answer might be updated, as soon as something changes.
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