Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add flag to treat @import URLs as opaque #823

Closed
wants to merge 1 commit into from

3 participants

@jamesrdf

Not every @import URL will end in .css or .less, some may include a query string to generate the CSS or LESS dynamically. This patch adds an "opaque" boolean flag to the less.Parser parameter and if true will cause all import URLs to be the same: never append ".less" and always inline the style rules.

Some example @import would be:
@import url("style.cgi?lang=en");
@import url("style.cgi?format=lesscss");

@lukeapage
Owner

I'm not sure if opaque is a good option name..
also this is only an issue for less.js in the browser right?
also you could add &dummy=.less on to the end to get around this issue?

@jamesrdf

I am using less.js on server side and want to combine all less and css files into one.

The &dummy=.less is a workaround, but requires editing all @import rules, which is not desirable in my situation.

@matthew-dean

There may be a more elegant solution. See the thread at the bottom of issue #315.

@lukeapage lukeapage closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 4, 2012
  1. @jamesrdf
This page is out of date. Refresh to see the latest.
Showing with 4 additions and 4 deletions.
  1. +1 −1  lib/less/parser.js
  2. +3 −3 lib/less/tree/import.js
View
2  lib/less/parser.js
@@ -1084,7 +1084,7 @@ less.Parser = function Parser(env) {
if (dir && (path = $(this.entities.quoted) || $(this.entities.url))) {
features = $(this.mediaFeatures);
if ($(';')) {
- return new(tree.Import)(path, imports, features, (dir[1] === 'once'), index);
+ return new(tree.Import)(path, imports, features, (dir[1] === 'once'), index, env);
}
}
},
View
6 lib/less/tree/import.js
@@ -11,7 +11,7 @@
// `import,push`, we also pass it a callback, which it'll call once
// the file has been fetched, and parsed.
//
-tree.Import = function (path, imports, features, once, index) {
+tree.Import = function (path, imports, features, once, index, env) {
var that = this;
this.once = once;
@@ -20,13 +20,13 @@ tree.Import = function (path, imports, features, once, index) {
this.features = features && new(tree.Value)(features);
// The '.less' extension is optional
- if (path instanceof tree.Quoted) {
+ if (path instanceof tree.Quoted && (!env || !env.opaque)) {
this.path = /\.(le?|c)ss(\?.*)?$/.test(path.value) ? path.value : path.value + '.less';
} else {
this.path = path.value.value || path.value;
}
- this.css = /css(\?.*)?$/.test(this.path);
+ this.css = /css(\?.*)?$/.test(this.path) && (!env || !env.opaque);
// Only pre-compile .less files
if (! this.css) {
Something went wrong with that request. Please try again.