CSS sourcemaps
See original GitHub issueClear and concise description of the problem
CSS sourcemaps aren’t currently supported, which can make it difficult to track down where a particular style was authored. It would be cool if they were preserved in both build (<link>
) and dev (<style>
) mode.
You can see this with a vanilla app (npm init @vitejs/app
and choose ‘vanilla’), and inspecting the #app
styles in both dev
and serve
. In dev
:
In serve
:
Ideally the top right would say ‘style.css’ in both cases.
Suggested solution
I don’t pretend to know exactly what would be involved, but elsewhere in the codebase magic-string
is used for a similar purpose. Presumably the relevant plugin is https://github.com/vitejs/vite/blob/main/packages/vite/src/node/plugins/css.ts. I could take a run at it if someone gave me a pointer or two.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:54
- Comments:8 (2 by maintainers)
Top Results From Across the Web
Getting started with CSS sourcemaps and in-browser Sass ...
CSS sourcemaps allow the browser to map CSS generated by a pre-processor, such as Sass, back to the original source file, including exactly ......
Read more >Should I Use Source Maps in Production? | CSS-Tricks
It's a valid question. A “source map” is a special file that connects a minified/uglified version of an asset (CSS or JavaScript) to...
Read more >How to Create CSS Map File - CSSDeck
CSS map file (source map) enables browsers to map CSS created by a preprocessor, such as Sass, Back to the original source file,...
Read more >Using source maps in Sass - Mario Araque
One of the new features in Sass 3.3 is source maps. We can use it to improve the debugging of our Sass code...
Read more >Use a source map — Firefox Source Docs documentation
A source map is a file that maps from the transformed source to the original source, enabling the browser to reconstruct the original...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Spent some time on this recently and here’s what i found.
map
from compileCss in vite:css [2] doesn’t work [3] as it would need to be transformed to an actual SourceMap first [4]Figuring out how to pass on the sourcemaps is different for dev and build, both coming with their own set of challenges. During dev, css is served from special js modules managing style nodes on the fly. So i think the easiest shot at this would be to add inline sourcemaps to that.
For build it’s a lot more difficult as css gets bundled too and sourcemaps have to be updated to reflect that and on top esbuild css minification needs to be accounted for too.
One Idea i had about this is to keep the css sourcemap inline as long as possible to avoid having to change any api where currently only
code
is passed on, extracting them to .map at the last second if it’s configured for external.Building all of this at once could prove challanging and hard to review, so i suggest to split it into smaller goals, which can be described in more detail separately and implemented on top of each other, for example
and also state which compromises can be made, eg
Would love some more 👀 on this.
– links [1] https://github.com/vitejs/vite/issues/649 [2] https://github.com/vitejs/vite/pull/4880 [3] https://github.com/vitejs/vite/pull/4939 [4] https://github.com/vitejs/vite/pull/4951
I noticed in the docs there is a css.devSourcemap option, but when I enabled it, it didn’t seem to change anything. Chrome dev tools still didn’t recognize my CSS styling as coming from Bootstrap’s
.scss
files, like it does in React’s Webpack dev server output.