I am using LESS compiler via a gulp-less in my gulpjs build. I have enabled sourceMap generation, and it kind of works, the proper file names and line numbers are there.
The gulp line that generates LESS with source maps is very straight-forward:
var less = require('gulp-less');
// [...]
gulp.src('web/css/**/*.less')
.pipe(less({
sourceMap: true
}))
.pipe(gulp.dest('dist/css'));
The only problem is that the source map contains a URL to the original .less file and it is generated as an absolute path to my file system, e.g. /Users/myuser/projects/project/web/css/myfile.less
.
During development, I serve the site via Apache. When I open the site with Chrome DevTools, I can inspect elements, and the source map is working because I can see the myfile.less
including correct line numbers on the Styles panel. However, Chrome is trying to load the less file, and it is using the full path is the sourcemap output but assuming it's a relative url to my site, so it tries to load http://localhost/Users/myuser/projects/project/web/css/myfile.less
which doesn't exists.
I tried using workspaces to fix it, but didn't really manage. Is there something wrong in this setup? Am I missing something?
I think you're missing these final steps:
Reload the dev tools (you'll get a prompt) and you should be good. Now, when you click on the foo.less:45
in the Styles panel, you should be brought to that spot in foo.less
. Now that you've setup the workspace, if you save your changes in the dev tools, it will persist to the source less file. Nice!
Note there's a pretty big bug with Chrome which you'll probably notice right away. When you go to add style rules via the dev tools, the source mapping gets busted: https://github.com/less/less.js/issues/1050#issuecomment-26195595
Let me know if this helps. I can post screenshots later, too, if needed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With