Grunt Contrib Less - Sourcemaps -- sourceMapRootpath and sourceMapBasepath ignored

561 views Asked by At

Ok - I'm trying to configure less to spit out a sourcemap and correctly point to the accessible path of the less files. I can get the sourcemap to work properly, but the path it dumps into the sources array in the source map file are always incorrect. Nothing I do to the sourceMapBasepath or sourceMapRootpath properties change the sources array.

Here's the options config in the

options: {
    paths: ['/app/content/less'],
    yuicompress: true,
    sourceMap: true,
    sourceMapFilename: "WebUI/app/content/css/app.css.map",
    sourceMapURL: "/app/content/css/app.css.map",
    sourceMapBasepath: '/app/content/less',
    sourceMapRootpath: '/'
},
files: {
    "./WebUI/app/content/css/app.css": "./WebUI/app/content/less/app.less"
}

That always spits out a sources array that lists files with this folder structure:

/WebUI/app/content/less/filename.less

The WebUI folder is the webroot - I don't want that there. I've tried a million variations of what I show above and nothing I add to sourceMapBasepath or sourceMapRootpath makes a difference.

Any ideas? Thanks

2

There are 2 answers

0
SDG On

My temporary fix is to output the source files in the source map - this is good enough, but still curious as to why I can't get the path to the less files to be correct.

0
Oleksandr Shybystyi On

I had the same problem and drawn a conclusion that sourceMapRootpath works but sourceMapBasepath is ignored.

According to soruceMapRootpath description

Adds this path onto the less file paths in the source map.

In your example you set

sourceMapRootpath: "/"
    + 
"./WebUI/app/content/less/app.less" (taken from files object) 
    = 
"/./WebUI/app/content/less/app.less"

and maybe there are some optimizations which make "/./" convert to "/".

Pretty weird though that you got "filename.less" instead "app.less".

Solution

So in order to solve your problem I would recommend to set:

sourceMapRootpath: '../../../../'

That should result in

../../../.././WebUI/app/content/less/app.less

in ./WebUI/app/content/css/app.css.map file.