Skip to content

Allow creating a source map #1050

@lukeapage

Description

@lukeapage
Member

see sass/sass#569

and #1038

We should output source maps in the new format

Activity

uzikilon

uzikilon commented on Jan 17, 2013

@uzikilon

+1

gabeidx

gabeidx commented on Jan 17, 2013

@gabeidx

👍

mrdevinmob

mrdevinmob commented on Jan 17, 2013

@mrdevinmob

+1

matthew-dean

matthew-dean commented on Jan 18, 2013

@matthew-dean
Member

+2

madcampos

madcampos commented on Feb 16, 2013

@madcampos

+1

Soviut

Soviut commented on Feb 16, 2013

@Soviut

+1, obviously!

EarMaster

EarMaster commented on Feb 27, 2013

@EarMaster

+1

aredridel

aredridel commented on Feb 27, 2013

@aredridel

+1

lukeapage

lukeapage commented on Feb 27, 2013

@lukeapage
MemberAuthor

if anyone wants to work on this

https://github.com/cloudhead/less.js/tree/import-interpolation

now has a visitor pattern implemented.

you should be able to use this to go over the nodes and grab original input information.

What you don't know is the target (css) line number.

To do that I would suggest having functions on the toCSS env object which build up the css and keep track of the current line number. You can then store that line number against the node.

After that it should be simple.

madcampos

madcampos commented on Feb 27, 2013

@madcampos

i'm not good at compiler theory (in fact i am at this course at college now) and haven't looked up less' code, but can't just write to a variable say, lineNumber and at each line break increment it? it should keep the line number state, after that it could be exposed to the function mapping the lines.

lukeapage

lukeapage commented on Feb 27, 2013

@lukeapage
MemberAuthor

@madcampos

yes.. that is this bit of the implementation I described.

having functions on the toCSS env object which build up the css and keep track of the current line number.

you need to keep track of the line number on the env object but also store its current value against each node as you output the css, then the ast has the source and the target line numbers and a mapping can be made.

jyonker

jyonker commented on May 22, 2013

@jyonker

+1

matthew-dean

matthew-dean commented on Jun 4, 2013

@matthew-dean
Member

lol, we're all for it, looks like we just need an adept JavaScript / LESS programmer to fix it up and do a pull request. ;-)

100 remaining items

nextgenthemes

nextgenthemes commented on Sep 16, 2013

@nextgenthemes

@duncanmcdowell Looks like you just forget to install it globally. In case you are on Ubuntu or the like as well and use chromium and followed the sandbox thing I described above, I was able to handle that in a better way now.

I also recommend using the npm install -g less@beta rather then pointing to some files on github since this works fine and will pull always the most up to date beta.

I have written up a more detailed HowTo to make this work on Ubuntu and friends. Check it out, I hope this helps somebody. http://nextgenthemes.com/2013/09/howto-get-less-sourcemaps-to-work-in-ubuntu-with-chromium/

hansipete

hansipete commented on Sep 24, 2013

@hansipete

@nextgenthemes thank you for your blogpost. it helped me getting it running with webstorm. i installed the latest less beta and have the following settings in webstorm file watcher:
bildschirmfoto 2013-09-24 um 17 18 06

scarlac

scarlac commented on Oct 2, 2013

@scarlac

For those using CodeKit.app I can recommend writing a small node.js script and using that script as the "compiler" for the 1.5 beta. That way you don't have to recompile it manually to get sourcemaps. My script seems to work for me, but it may contain bugs or needs to be adjusted for your environment.
https://gist.github.com/scarlac/6793066

denisos

denisos commented on Oct 2, 2013

@denisos

Hi all, this is beautiful, thank you!
Here's the steps I followed to get it working for my dev env:

  • Chrome v30 (I have Version 30.0.1599.66 to be exact)
  • I ensured that in Chrome Gears->General both these are checked: "Enable CSS source maps" and "Auto-reload generated CSS"
  • I got the latest lessc 1.5 beta from node: "sudo npm install -g less@beta"
    Install worked fine (once lessc 1.5 is released then no need to do this I assume)
  • I build using lessc: "lessc --line-numbers=all --source-map=main.css.map main.less >main.css"
  • I reload my app and can debug the less styles. I load from localhost hitting apache to serve my html and files, I understand from previous comments that files must be served from a web server, cannot be loaded direct from filesystem.

tip: type "lessc" to --line-numbers and --source-map choices

The --source-map setting was critical for me to get it working. I set it to follow the filename of my final generated css.

seven-phases-max

seven-phases-max commented on Oct 2, 2013

@seven-phases-max
Member

... that files must be served from a web server, cannot be loaded direct from filesystem.

Btw., Chrome has "-allow-file-access-from-files" command line option so it's actually possible to test/debug your pages w/o a web server...

dotnetwise

dotnetwise commented on Oct 3, 2013

@dotnetwise

Even with -allow-file-access-from-files the css source maps are still not being loaded in Chrome canary 32.0.1658.2 when opening html files via file:// protocol. Javascript source map do load.

neochief

neochief commented on Oct 3, 2013

@neochief

To whoever still can't figure out how to make it work, this might save few hours of debug.

If you use webserver, you should define --source-map-rootpath options to be equal to your website base path. For example, if you debug http://website.com/styles/style.css (and the less file is present at the same location, e.g. http://website.com/styles/style.less), here's how you compile command should look like:

lessc --line-numbers=all --source-map-rootpath=http://website.com --source-map=styles/style.css.map styles/style.less styles/style.css

If it still does not work, check your generated css file. At the very bottom it should have something like this:

/*# sourceMappingURL=http://website.com/styles/style.css.map */

this should be a full URL to the source map, which could be opened in chrome. It it's correct, everything should work fine. If not, keep playing with arguments.

I can confirm this with less v.1.5b3, Chrome 29 and Canary 32 (with no special command line arguments).

25 remaining items

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @aredridel@evocateur@paulirish@addyosmani@retlehs

        Issue actions

          Allow creating a source map · Issue #1050 · less/less.js