sass / node-sass

:rainbow: Node.js bindings to libsass
https://npmjs.org/package/node-sass
MIT License
8.5k stars 1.33k forks source link

Ability to pass previous source map content #2860

Open yuri-karadzhov opened 4 years ago

yuri-karadzhov commented 4 years ago

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);
saper commented 4 years ago

How should it work?

yuri-karadzhov commented 4 years ago

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.

nschonni commented 4 years ago

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

hqjs commented 4 years ago

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.

saper commented 4 years ago

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?

mgreter commented 4 years ago

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.