Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Embed Sourcemaps #591

Closed
iamvdo opened this issue Dec 29, 2014 · 7 comments
Closed

Embed Sourcemaps #591

iamvdo opened this issue Dec 29, 2014 · 7 comments

Comments

@iamvdo
Copy link

iamvdo commented Dec 29, 2014

I'm testing out the new 2.0.0-beta and try to inline sourcemaps, but it fails. My simple demo:

var fs = require('fs');
var sass = require('node-sass');

var css = fs.readFileSync('in.scss', 'utf-8');

css = sass.renderSync({
  data: css,
  sourceMap: true,
  sourceMapEmbed: true
});

fs.writeFileSync('out.css', css.css);
  • It doesn't inline sourcemaps when sourceMap and sourceMapEmbed are set to true.
  • It inlines when sourceMap is set to process.cwd() or any other path for example, but sourcemaps are badly generated. Plus I don't want to specify a path because I use data.

What am I doing wrong ?

@am11
Copy link
Contributor

am11 commented Dec 29, 2014

What am I doing wrong ?

Not setting outFile. You need to at least set outFile option to make the sourceMap generated. Not that we are going to write on that path, but it is required by source-map itself. Also with data option, you can also set file, because libsass will always give precedence to data when both options are set. Setting outFile and file add those paths in source-maps file: and sources[] options respectively. Setting file options will also prevent libsass from putting stdin in sourceMap sources array. That is the whole point of sourcemaps, to have a source-to-source mapping in trans-compilation scenarios.

// comma-first style so you can comment out (enable/disable) options easily
var result = require("node-sass").renderSync({
    data: "a{b:c}"
  , file: "/some/random/path.scss"
  , outFile: '/temp/foo.css'
  , sourceMap: true
  , sourceMapEmbed: true
  , sourceMapContents: true
});

console.warn(result);

Plus I don't want to specify a path because I use data

sourceMap option should be set to true or an absolute or relative path, to make other sourceMap related options take effect. So nothing wrong there.

but sourcemaps are badly generated.

Define "badly". An example of generated code would suffice.

@iamvdo
Copy link
Author

iamvdo commented Dec 29, 2014

Not setting outFile

OK, this could be clearer in docs imo. To make sourcemaps works, file AND outFile have to be set.

Define "badly". An example of generated code would suffice.

If I take this code (with many blank lines):

$color: red;


















.element {
  color: $color;
}

Sourcemaps always reference .element on line 1, whether it's on line 20.

@am11
Copy link
Contributor

am11 commented Dec 29, 2014

this could be clearer in docs imo

I agree. PRs are most welcome! 😃

Sourcemaps always reference .element on line 1

This belongs to libsass, but it is already fixed there sass/libsass#775. In next release of node-sass (beta2 probably), this will be fixed.

@iamvdo
Copy link
Author

iamvdo commented Dec 29, 2014

Great !
Thank you.

I will make a PR soon ;)

@iamvdo iamvdo closed this as completed Dec 29, 2014
@am11
Copy link
Contributor

am11 commented Dec 29, 2014

To make sourcemaps works, file AND outFile have to be set

This behavior is actually fixed for the upcoming release. Only outFile option is the condition. BTW it is not something which libsass has documented either. With every release these tiny flags alter behavior.

@xzyfer
Copy link
Contributor

xzyfer commented Dec 29, 2014

BTW it is not something which libsass has documented either

Wiki edits welcome 😉 https://github.com/sass/libsass/wiki

@am11
Copy link
Contributor

am11 commented Dec 29, 2014

@xzyfer sure thing! 😄

We should also maintain a wiki here for node.js API.

Momentarily, I have created a #libsass channel on IRC under freenode. Come join!

//cc @mgreter

jiongle1 pushed a commit to scantist-ossops-m2/node-sass that referenced this issue Apr 7, 2024
[WIP] Implements embedding source contents in source maps
jiongle1 pushed a commit to scantist-ossops-m2/node-sass that referenced this issue Apr 7, 2024
- Remove line-breaks in Base64 encoded string
- Actually embed the source-map json in data-url
- Include original source in sources array
jiongle1 pushed a commit to scantist-ossops-m2/node-sass that referenced this issue Apr 7, 2024
[BUGFIX] Add fix for source-maps (Fix-Up PR sass#591)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants