0

Is it possible to display the CSS that Less.js generates?

I have the following page:

<!doctype html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>Less</title>
        <link rel="stylesheet" type="text/less" href="test.less">
        <script type="text/javascript">
            less = {
                env: "development", // or "production"
                async: false,       // load imports async
                fileAsync: false,   // load imports async when in a page under
                                    // a file protocol
                poll: 1000,         // when in watch mode, time in ms between polls
                functions: {},      // user functions, keyed by name
                dumpLineNumbers: "comments", // or "mediaQuery" or "all"
                relativeUrls: false,// whether to adjust url's to be relative
                                    // if false, url's are already relative to the
                                    // entry less file
                rootpath: ":/a.com/"// a path to add on to the start of every url
                                    //resource
            };
        </script>
        <script src="less-1.5.0.min.js" type="text/javascript"></script>
    </head>
    <body class="default">

        <script>

            console.log(less);

        </script>

    </body>
</html>

The CSS is working fine, but I want to see what the 'actual' generated CSS file looks like. I can't see anything in the object less that seems to contain it...

3
  • Would using a pre-processor be a possibility ? I mean you could process less file on your local machine to see it, and either put the generated CSS online, either keep on "compiling" it client-side. Commented Dec 3, 2013 at 11:06
  • I will be doing. I just want to see it with the Less.js version that's all. Commented Dec 3, 2013 at 11:07
  • I may be missing something, but aren't you suppose to do some kind of action to initiate client-side "compilation" ? Or is it done automatically upon inserting the less.js file ? Cause your less object looks just like settings... Commented Dec 3, 2013 at 11:20

3 Answers 3

3

From LESS - The dynamic stylesheet language.

Debugging
It is possible to output rules in your CSS which allow tools to locate the source of the rule.
Either specify the option dumpLineNumbers as above or add !dumpLineNumbers:mediaQuery to the url.
You can use the “comments” option with FireLESS and the “mediaQuery” option with FireBug/Chrome dev tools (it is identical to the SCSS media query debugging format).

A quick glance through https://github.com/less/less.js/blob/master/dist/less-1.5.1.js shows function createCSS(styles, sheet, lastModified) in line 6344. From this function, I would say less creates a style element, where the resulting CSS is placed. So, something like this might work

var css = $('style').text();
console.log(css);

JSFiddle

Sign up to request clarification or add additional context in comments.

1 Comment

Boom :) Thanks that's exactly what I want.
1

Use vLESSlook tool (js/vlesslook.js and css/vlesslook.css). See readme - this not only for Python / Django - JavaScript and CSS you can use anywhere..

Comments

0

Read the Browser Options http://lesscss.org/#client-side-usage

<script>
  less = {
    env: "development",
    async: false,
    fileAsync: false,
    poll: 1000,
    functions: {},
    dumpLineNumbers: "comments",
    relativeUrls: false,
    rootpath: ":/a.com/"
  };
</script>
<script src="less.js"></script>

Make sure the dumpLineNumbers is set to "comments",

Open the DOM explorer of your browser(In my case Firefox -> FireBug) and in <head> look for <style id="less:User...." >. There is your CSS with comments, lines and files where the generated CSS rules come from.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.