Closed netAction closed 10 years ago
Well, it depends on various factors (first of all why cleant-side script? is it some kind of web-app?). But in general I guess you'd better start with an explicit compiler instance instead of borrowing a result of the automatic in-browser compilation. Something similar to http://stackoverflow.com/a/25325750.
(I'm marking this for closing since "How-To" Less questions do not really belong here. SO is a better place for this).
Thanks a lot! This solves issues 1 and 3. Why is it possible for less to read the local file referenced in the LINK element but not by reading with jQuery get()?
$.get("css/style.less", function(lessCode) {
new(less.Parser)().parse(lessCode, function (e, tree) {
$('pre').text( tree.toCSS() );
});
});
but not by reading with jQuery get()
Honestly I have no idea. Does this get()
really return a valid source string to the callback? If I'm not mistaken such minimal get
form is meant to work only with casual mime types (xml, json, script, or html) and to get less
file content you need to supply more specific parameters there...
Yes, it works on http. Might depend on the mime type the server sends, dunno.
Mm, I made this codepen and it seems to work fine... (though the less file there is at https
but I wonder if it makes the difference, hmm, and also the gist server may actually return it as a plain mime-text
type and this probably can affect things too).
Are there any specific errors in the console?
The error occus only when running the script without web server. Chromium says:
XMLHttpRequest cannot load file:///home/tomi/*****/css/script.less. Received an invalid response. Origin 'null' is therefore not allowed access. getCss.html:1
And Firefox:
Not well formed.
Note that Chrome by default does not allow scripts to access local files (see http://stackoverflow.com/a/18531239). Firefox should work with local files out of the box. Either way in both cases it looks like something being wrong with the file path rather then something Less specific.
Closing as not a Less issue.
What is the right way to export the CSS into a file? At the moment I am doing this:
But there are several issues.