The @import rule is the legacy way of splitting styles across multiple files
in Sass. The @use rule should generally be used instead, but @import is
still supported for backwards-compatibility.
To execute an @import rule rule:
-
For each of
rule's argumentsargument:-
If any of the following are true,
argumentis considered "plain CSS":argument's URL string begins withhttp://orhttps://.argument's URL string ends with.css.argument's URL string is syntactically defined as aurl().argumenthas a media query and/or a supports query.
Note that this means that imports that explicitly end with
.cssare treated as plain CSS@importrules, rather than importing stylesheets as CSS. -
If
argumentis "plain CSS":-
Evaluate any interpolation it contains.
-
Add an
@importwith the evaluated string, media query, and/or supports query to the current module's CSS AST.
-
-
Otherwise, let
filebe the result of loading the file withargument's URL string. If this returns null, throw an error. -
If
file's canonical URL is the same as that of any other current source file, throw an error. -
Let
importedbe the result of executingfilewith the empty configuration and the current import context, except that ifruleis nested within at-rules and/or style rules, that context is preserved when executingfile.Note that this execution can mutate
import. -
Let
cssbe the result of resolvingimported's extensions, except that ifruleis nested within at-rules and/or style rules, that context is added to CSS that comes from modules loaded byimported.This creates an entirely separate CSS tree with an entirely separate
@extendcontext than normal@uses of these modules. This means their CSS may be duplicated, and they may be extended differently. -
Add
cssto the current module's CSS. -
Add
imported's extensions to the current module. -
If the
@importrule is nested within at-rules and/or style rules, add each member inimportedto the local scope. -
Otherwise, add each member in
importedto the current import context and the current module.
Members defined directly in
importedwill have already been added toimportin the course of its execution. This only adds members thatimportedforwards.Members from
importedoverride members of the same name and type that have already been added toimportandmodule. -