-
Notifications
You must be signed in to change notification settings - Fork 47
Analysis Under Development
Attempts to import css and less files are treated differently and so it is important to understand what is considered CSS file and what is considered less file. If the file name ends with suffix ".css", then the file is considered to be CSS file. Otherwise it is considered to be less file. Less.js supports also url parameters at the end of the name e.g., file.css?id=123
is considered CSS file.
CSS file import statements remain unchanged during the compilation. However, they may change the location during the compilation. All top-level CSS file import statements are printed at the beginning of the style sheet right after the charset
declarations.
Sample input/output as compiled by less.js-1.3.3:
|
|
Content of imported less file is copied into the main file. All mixins, namespaces, variables etc. are going to be available and can used inside the main file. If the import statement contains also media queries, file content is enclosed in into the body of @media
statement.
Imported less file is copied compiled before the compilation. Imported file can reference any mixin or variable defined in the main file and main file can reference anything defined in the imported file.
First example shows import statement with and without media queries. Import\imported-1.less file:
h1 {
color: red;
}
main file as compiled by less.js-1.3.3:
|
|
Second example shows referencing between imported and main files. Imported file import\needs-main-mixin.less file:
importedSelector {
.mainMixin(); // mixin is defined in main file
.importedMixin();
}
.importedMixin() {
content: "imported mixin";
}
@variable: 3; // main file contains variable with the same name
main file as compiled by less.js-1.3.3:
|
|
Finally, if the import statement contains media query and is placed inside a ruleset, @media statement will bubble up as usually:
|
|
TODO
Import-once statement imports the same less file only once. It does not matter whether you place it on style sheet top level or inside a ruleset nor whether it has media query attached to it or not nor whether it uses string or url(...)
. The same file is included only once.
Sample input:
@import-once "import\imported-1.less" screen and (max-width: 400px);
@import-once "import\imported-1.less" handheld; //this will be ignored
@import-once url(import\imported-1.less); //this will be ignored
#namespace {
@import-once "import\imported-1.less"; //this will be ignored
}
is compiled into:
@media screen and (max-width: 400px) {
// imported-1.less content
}
Import-once of css files works differently:
|
|
TODO: ask less.js whether this is how it should be.
Import-multiple statement will be available after 1.4.0 comes out. It imports the same less file any number of times.
Sample input:
|
|
The import statement in current less.js acts as @import-multiple
. This will change in 1.4.0. The import statement will be modified to act as @import-once
.
TODO
TODO import-once and import-multiple on css files are converted to import statements TODO variables and escaped values TODO less4j supports only top-level imports for now.
|
|