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

sourceMapEmbed and sourceMapContents doesn't work as expected while compiling to string #1425

Closed
JohnyCilohokla opened this issue Aug 6, 2021 · 1 comment

Comments

@JohnyCilohokla
Copy link

I'm using the library to compile the scss during runtime by using renderSync and modifying the require function to inject the compiled scss into the dom, I want to embed the sourceMap and the source to css output.

The following will not work:

let rendered = sass.renderSync({
	file: "./source/test.scss",
	sourceMapContents: true,
	sourceMapEmbed: true
});
let style = rendered.css.toString();

This code will also not work:

let rendered = sass.renderSync({
	file: "./source/test.scss",
	sourceMap: true,
	sourceMapContents: true,
	sourceMapEmbed: true
});
let style = rendered.css.toString();

I could only get it to work by specifying the sourceMap parameter as a string, but I would expect that to produce a file for the sourceMap, like so:

let rendered = sass.renderSync({
	file: "./source/test.scss",
	sourceMap: "",
	sourceMapContents: true,
	sourceMapEmbed: true
});
let style = rendered.css.toString();

Expected behavior: sourceMapEmbed and sourceMapContents should still work while compiling to string, either by having the sourceMap set to true or not requiring sourceMap to be set at all.

@JohnyCilohokla JohnyCilohokla changed the title sourceMapEmbed and sourceMapContents doesn't work while compiling to string sourceMapEmbed and sourceMapContents doesn't work as expected while compiling to string Aug 6, 2021
@jathak
Copy link
Member

jathak commented Aug 18, 2021

It's unintuitive, but the JS API docs do specify that sourceMap: true will be ignored if outFile is not set. Passing a string when you want an embedded source map is indeed what you should do here.

We do have a proposal out for a new JS API (that's not yet available, but will be in the future) if you have any comments on it: sass/sass#3056

@jathak jathak closed this as completed Aug 18, 2021
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

No branches or pull requests

2 participants