node-sass icon indicating copy to clipboard operation
node-sass copied to clipboard

Ability to pass previous source map content

Open yuri-karadzhov opened this issue 4 years ago • 6 comments

At the moment there is no possibility to pass previous source map content it would be nice if sourceMap option will be able to receive previous source map object and use it to generate new source map.

sass.render({
      data,
      sourceMap: prevSourceMapObject
}, handleResult);

yuri-karadzhov avatar Mar 16 '20 11:03 yuri-karadzhov

How should it work?

saper avatar Mar 18 '20 09:03 saper

Same way as with other compilers e.g. postcss I guess. If your scss is result of precompilation and has source map content already it is pity to lose it after compilation with node-sass. Actually it works with postcss-node-sass, but it is hacky and postcss people recommend to use node-sass directly.

yuri-karadzhov avatar Mar 21 '20 21:03 yuri-karadzhov

I don't think this is something for node-sass/libsass. PostCSS is a good idea, but node-sass is the start of the compilation chain, there is nothing that Sass in general would do with existing source maps coming from things like plain CSS files. Pass the compiled node-sass and any other CSS you're trying to concatenate to PostCSS that already knows how to combine source maps

nschonni avatar Mar 21 '20 21:03 nschonni

Well, in my case https://hqjs.org it is not, I have additional step before node-sass to make it work with paths. So far it does not change files significantly so should be Ok without source map, but I can assume there might be some useful plugins that transform scss into scss so it might become a thing at some point.

hqjs avatar Mar 21 '20 21:03 hqjs

Would that be possible to create a simple demo repository to demonstrate the case - and most importantly to show what the expected output would be?

saper avatar Mar 24 '20 11:03 saper

IMO this is a feature libsass already has on the wish-list, but it is prioritized very very low. The related ticket would be https://github.com/sass/libsass/issues/668 And https://github.com/sass/node-sass/issues/1584 seems to be a duplicate of this.

Btw. the use case is simple to explain, given input A and B create an intermediate file C, which is then processed by libsass, we would like the resulting mappings to point to A and B and not C. The connection from C back to A and B is represented by the sourcemap you would pass in.

mgreter avatar Apr 19 '20 20:04 mgreter