-
Notifications
You must be signed in to change notification settings - Fork 254
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
Source maps generated in SASS output is unusable as served by trunk #899
Comments
Hm, so it might make sense to keep the original path prefix ( |
I'm not sure that helps. In general, the generated CSS file and its source map (bundled or not) will end up in |
Ok, I see. Thanks for explaining it. So maybe it makes sense to have |
Yes, that seems like a good solution to me. In addition it might make sense to stop using the |
Ok, I think I have a problem understanding the difference between |
Ok, so on a fundamental level, sass turns a set of sass/scss file into one monolithic CSS file, i.e. when we originally had How exactly this mapping is communicated to the browser depends on various options, among them
Note how we are talking about two different levels of indirection here:
Using So the two options do similar, but ultimately orthogonal things. I think they are both relevant here, because |
Thanks for the thorough explanation! I believe I have a much better understanding of this now. So a quick fix would be to use both flags for debug mode. And none for release mode. A better approach might be to use |
Yes exactly, that matches my understanding. |
Ah, there's some subtlety here, that I didn't account for. Even with a separate /*# sourceMappingURL=foo.css.map */ This comment is usually generated by the sass compiler, so the included path doesn't include the digest generated by trunk. So if we drop |
I just noticed that I messed up the option name for the entire conversation. The option to include source files in the generated source map, previously referred to as |
When including SCSS or SASS assets in debug build, they are compiled using the
--embed-source-maps
option, which causes a source map to be genrated and included directly in the generated CSS asset. Unfortunately, this doesn't actually make it possible to actually use the source map in a browser to inspect the individual mapped sources of the CSS file. This is because the generated source file, doesn't contain the source code of the component files themselves, but merely references them via relative paths. But since the original source files will usually not be served along with the generated output, the browser won't be able to download those source files to display the correct source.As an example, if I include a SCSS asset like this
and build it such that the HTML will be available at
http://example.com/index.html
, then the source map included inhttp://example.com/app-<hash>.css
will reference the relative pathstyles/app.scss
, causing the browser to requesthttp://example.com/styles/app.css
and treat the result as the expected source file. In the case of using the trunk development server, this won't return the expected source file, but will instead return theindex.html
, causing that to be displayed as the source file for the generated CSSThis leads to arguably worse results than having no source map at all, since e.g. Firefox will prefer to display the mapped source instead of the generated source if a source map is available, which in this case causes no actual CSS source to be displayed at all.
A relatively simple solution to this problem could be to call the sass compiler with
--include-sources
, which causes the source files to be included verbatim in the source map. Of course this also considerably increases the size of the source map, so it might be worth considering to remove the--embed-source-maps
option altogether and instead copy the separate source map into the dist directory, so browser can fetch it independently of the CSS on demand.The text was updated successfully, but these errors were encountered: