postcss-import icon indicating copy to clipboard operation
postcss-import copied to clipboard

import-only files not in sourcemap

Open htho opened this issue 5 years ago • 6 comments

I have file that has only @import rules, but nothing else. This file can not be found in the sourcemap. If I add a dummy comment, the file is in the sourcemap.

Maybe this is related to: #81?

I created a minimally working example: https://github.com/htho/mwe-postcss-import-sourcemap-import-only

htho avatar Jul 08 '19 06:07 htho

PR welcome to fix this.

RyanZim avatar Jul 08 '19 16:07 RyanZim

Puh.

I wouldn't even know where to start. I have no clue about the interaction between postcss and postcss-import.

htho avatar Jul 08 '19 19:07 htho

If I add a dummy comment, the file is in the sourcemap.

That is the only way to "fix" this.

postcss-import removes @import statements and anything that is imported will be coming from other files.

If a file contains only @import statements it will never be part of the source maps.

We could automatically add a comment with the @import statement as comment text :
/* @import "foo.css" */

But any half decent minifier will scrub comments, re-introducing the issue.


I am also unsure what the use case is. Technically the file is missing from the source maps, but is this a problem? Sourcemaps should still work for all other CSS.

If so, which problem? Are there alternative solutions?

romainmenke avatar Jul 23 '23 09:07 romainmenke

We could automatically add a comment with the @import statement as comment text : /* @import "foo.css" */

esbuild seems to do something like this.


style.css :

@import url("a.css");

a.css :

.box {
	background-color: green;
}

becomes :

/* tests/001-core-features/001/default/a.css */
.box {
  background-color: green;
}

/* tests/001-core-features/001/default/style.css */

romainmenke avatar Aug 10 '23 21:08 romainmenke

If someone wants this badly enough they're willing to submit a PR, we can consider it. But I don't see the point of adding it just for the sake of it. So far, one request in ~4 years; doesn't seem to be a common need.

RyanZim avatar Aug 11 '23 18:08 RyanZim

Yeah, I also fail to see the issue.

I don't think the fact that it's missing from a sourcemap is breaking anything or can cause any inconvenience.

romainmenke avatar Aug 11 '23 18:08 romainmenke