postcss / postcss-import

PostCSS plugin to inline at-import rules content
MIT License
1.37k stars 116 forks source link

import-only files not in sourcemap #400

Open htho opened 5 years ago

htho commented 5 years ago

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

RyanZim commented 5 years ago

PR welcome to fix this.

htho commented 5 years ago

Puh.

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

romainmenke commented 1 year ago

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 commented 1 year ago

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 */
RyanZim commented 1 year ago

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.

romainmenke commented 1 year ago

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.