Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sourcemap basepath option #1543

Merged
merged 2 commits into from
Sep 14, 2013
Merged

Sourcemap basepath option #1543

merged 2 commits into from
Sep 14, 2013

Conversation

andjo
Copy link
Contributor

@andjo andjo commented Sep 11, 2013

I failed to create a correct source map unless standing in exactly right directory when running the lessc command.
I've added a --source-map-basepath option that is used in stead of process.cwd() if supplied, and also normalizing the path printed in the sourceMappingURL.

This is something that works for me right now, but I'm not sure it is the right thing to do. I have not tested it in other configurations. Merge with caution.

I can now invoke the command from my Gruntfile.js like this:

        shell: {
            less: {
                command: './node_modules/less/bin/lessc <%= lessSrc %> <%= davMountpoint %><%= templateDir %>/css/prd/main.less.css' +
                ' --source-map=<%= davMountpoint %><%= templateDir %>/css/prd/main.less.css.map' +
                ' --source-map-rootpath=/ns/' +
                ' --source-map-basepath=<%= davMountpoint %>',
                options: {
                    stdout: true,
                    stderr: true
                }
            }
        },

@@ -197,7 +202,7 @@ if (output) {
}
}

options.sourceMapBasepath = process.cwd();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if the only change that instead of being process.cwd() this should be the directory of the root less file.. then we are stripping this off every path and adding in the sourcemap rootpath.. would that work for you too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I understand. Backing out my change and only removing this line gives me lots o "/ns/(davMountpoint)/..." still in the paths.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, try replacing this with options.sourceMapBasepath = input ? path.dirname(input) : process.cwd()

If you could let me know if that works, that would be great

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That may work if all less files are in a subdirectory relative the input file. But my setup is like this:

/css/src/main.less
/css/prd/main.css
/css/vendor/bootstrap/

main.less does things like @import ../vendor/boostrap/less/variables.less and all output is placed in /css/prd/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It also only works if the "sources" references in the source map are relative, but I'm adding the rootpath prefix "/ns/" witch leads to paths like "/ns/main.less" where it should be "/ns/css/src/main.less".

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll take this pull request thanks, but also change the default in the way I suggested.

lukeapage added a commit that referenced this pull request Sep 14, 2013
@lukeapage lukeapage merged commit 0a70ede into less:master Sep 14, 2013
@andjo andjo deleted the sourcemap-options branch September 14, 2013 11:04
@andjo
Copy link
Contributor Author

andjo commented Sep 14, 2013

Excellent. The source maps are working very good by the way. 👍

@iamkevinv
Copy link

Just referenced #1740 to this one. Perhaps the basepath could help with the problem of being able to remove preceding parts of the paths written in the generated sourcemap file. Cheers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants