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

CLI: Support for input source maps #40

Closed
wkornewald opened this issue Aug 26, 2015 · 6 comments
Closed

CLI: Support for input source maps #40

wkornewald opened this issue Aug 26, 2015 · 6 comments

Comments

@wkornewald
Copy link

Maybe I've missed sommething, but input source maps don't seem to be taken into account. Our compiled Sass code has a source map, but rtlcss only maps back to the Sass' CSS output instead of the original Sass files.

Also, the generated source map file only contains the text "undefined" and the source map itself is inlined as a data URI in the output CSS.

@MohammadYounes
Copy link
Owner

but rtlcss only maps back to the Sass' CSS output instead of the original Sass files.

This is the expected behavior, since SASS CSS output is RTLCSS input.

the generated source map file only contains the text "undefined" and the source map itself is inlined as a data URI in the output CSS.

As of postcss 3.0 map.inline is enabled by default, which will cause source maps to be embedded inside the processed file, you need to explicitly set it to false.

 rtlcss([...]).process(css, {
    from: 'ltr.css',
    to:   'rtl.css',
    map: { inline: false },
});

@wkornewald
Copy link
Author

but rtlcss only maps back to the Sass' CSS output instead of the original Sass files.

This is the expected behavior, since SASS CSS output is RTLCSS input.

However, the Sass output also contains a source map, so it would be possible to map back to the original source, which makes debugging much easier. Currently we have to grep the whole project because we have lots of small Sass modules. Other tools like Uglify support reusing intermediate source maps, too (e.g. so you can see the original Coffee source instead of some unreadable Coffee compiler output).

As of postcss 3.0 map.inline is enabled by default, which will cause source maps to be embedded inside the processed file, you need to explicitly set it to false.

I forgot to mention, we're using the cli (via a custom build system written in Python). The cli's source map output seems to be broken. If the source map is supposed to be inline, why does it generate a .map file with "undefined"? Otherwise the cli should set inline: false.

@MohammadYounes
Copy link
Owner

so it would be possible to map back to the original source

Sure, but still you need to pass the previous source map too

rtlcss([...]).process(css, {
    from: 'ltr.css',
    to:   'rtl.css',
    map: { 'inline': false, 'prev': previousMap },
});

The cli's source map output seems to be broken. If the source map is supposed to be inline, why does it generate a .map file with "undefined"? Otherwise the cli should set inline: false.

True, the CLI was written prior to postcss 3.0 release, it should be updated to set inline:false.

However, to make sure the fix will solve your problem, can you try running your build with a modified version of the CLI. Just update this line to:

    opt.map = {inline:false, prev:true};

And make sure your config has map:true.

Thanks.

@MohammadYounes MohammadYounes changed the title Support for input source maps CLI: Support for input source maps Aug 27, 2015
@MohammadYounes
Copy link
Owner

@wkornewald According to my tests, when the processed CSS file contains a reference to an external map file then setting map config option to true is sufficient enough. Otherwise you need to set it to {inline:false}.

@wkornewald
Copy link
Author

@MohammadYounes Thanks. I've updated our build system and now it seems to work fine. The only issue left is that apparently on Windows there is a mixture of line endings in the generated css file. The code has \r\n, but the sourceMappingURL annotation comment uses \n.

@MohammadYounes
Copy link
Owner

That's caused by postcss, see this line.

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

No branches or pull requests

2 participants