lesscss-maven-plugin icon indicating copy to clipboard operation
lesscss-maven-plugin copied to clipboard

imports

Open iframeskills opened this issue 12 years ago • 13 comments

(thanks for the great plugin! small issue below:)

@media screen {
  @import "homepage.less";
  @import "searchresults.less";
}

-> fails

@media screen {
@import "homepage.less";
@import "searchresults.less";
}

-> does not fail.

Whitespace before imports seem to break compilation

/*@import "homepage.less";*/

also breaks. blocklevel comments and imports don't get along either.

iframeskills avatar May 24 '12 09:05 iframeskills

Hi @iframeskills,

I know imports can be a little bit cranky... The lesscss-maven-plugin uses my lesscss-java library (https://github.com/marceloverdijk/lesscss-java).

Resolving imports is done using a regexp pattern in https://github.com/marceloverdijk/lesscss-java/blob/master/src/main/java/org/lesscss/LessSource.java:

private static final Pattern IMPORT_PATTERN = Pattern.compile("^(?!\\s*//\\s*)@import\\s+(url\\()?\\s*\"(.+)\\s*\"(\\))?\\s*;.*$", MULTILINE);

I think this needs a little bit of tweaking...

marceloverdijk avatar May 24 '12 10:05 marceloverdijk

Perhaps this is a better regex?

^\s*(?!//)\s*@import\s+(url\()?\s*\"(.+)\s*\"(\))?\s*;.*$

And as for the block comments, it's always better to filter them out before parsing the file.

/\*.*?\*/

jandebleser avatar May 24 '12 11:05 jandebleser

Good point about filtering block comments before parsing; I will definitely add that!

Honestly, I'm very bad at reg exp, can you maybe explain your changes?

marceloverdijk avatar May 24 '12 11:05 marceloverdijk

I just changed the first part this:

(?!\\s*//\\s*)

into this (now with double backslashes):

\\s*(?!//)\\s*

What it does: The \s* allows whitespace, and the (?!//) disallows line comments. What you had before did not allow whitespace at all.

Thanks for the great plugin by the way :)

jandebleser avatar May 24 '12 11:05 jandebleser

And you could even omit the line comment part, since the whitespace rule will already filter it out. This would then be the regex (with double backslashes):

^\\s*@import\\s+(url\\()?\\s*\"(.+)\\s*\"(\\))?\\s*;.*$

jandebleser avatar May 24 '12 11:05 jandebleser

I'm seeing this issue as well - do you have a guess when this fix may be made? Thanks!

candrews avatar Jun 18 '12 16:06 candrews

+1

I just got caught out as well.

alanshaw avatar Jul 18 '12 14:07 alanshaw

I was waiting for a next less version...

marceloverdijk avatar Jul 18 '12 14:07 marceloverdijk

You might as well incorporate single quotes into the regex, as this is also valid:

@import 'file.less';

Regexes aside, have you considered not tying lesscss-java releases strictly to less.js?

disolovyov avatar Aug 28 '12 13:08 disolovyov

+1 to singe quotes in regex. This broke my build.

rweng avatar Dec 03 '12 12:12 rweng

+1 This just got me too. Was about to file an issue after tracking it down, only to realize I should have read this one first! =)

MattSenter avatar Dec 12 '12 19:12 MattSenter

I will look into it. Simple quote imports is fixed for 1.3.3. I need to reproduce the issue with white spaces.

cpopov avatar Mar 01 '13 17:03 cpopov

normally lesscss.js manages imports. But I am not sure how it will work in a Rhino environment. I am just thinking that if lesscss.js manages imports, maybe we shouldn't do a pre-processing with regexps.

cpopov avatar Mar 03 '13 15:03 cpopov