vitejs / vite

Next generation frontend tooling. It's fast!
http://vitejs.dev
MIT License
65.9k stars 5.88k forks source link

Pass Sourcemaps to PostCSS Plugins #14028

Open sgarfinkel opened 11 months ago

sgarfinkel commented 11 months ago

Description

Hi, the issue is basically this line: https://github.com/vitejs/vite/blob/6c323d5b3ab3cdf81d21bbe965ed3c36aa7f0589/packages/vite/src/node/plugins/css.ts#L1362

Unless there’s a compelling reason to leave this disabled, can we at least turn it on conditionally with a flag? Sourcemaps are required to resolve relative URLs in SASS imports.

Suggested solution

Uncomment this line.

Alternative

None, you’d have to write your own css plugin. Sourcemaps from postprocessors are lost under normal circumstances.

Additional context

No response

Validations

sapphi-red commented 3 months ago

Sourcemaps are required to resolve relative URLs in SASS imports.

Would you expand this a bit more? IIRC Vite does not rely on sourcemaps when resolving relative URLs in sass.

sgarfinkel commented 2 months ago

Sure, the use case is basically what this loader does: https://www.npmjs.com/package/resolve-url-loader

SASS often leaves relative URLs that are unresolvable in the final built CSS because they are meant to be resolved from the source file that you imported them from.

sapphi-red commented 2 months ago

So..., you are going to write our own postcss-plugin like what resolve-url-loader does? Won't that result in rebasing the URL twice as [Vite has a built-in feature for that](https://vitejs.dev/guide/features.html#css-pre-processors:~:text=Vite%20improves%20%40import%20resolving%20for%20Sass%20and%20Less%20so%20that%20Vite%20aliases%20are%20also%20respected.%20In%20addition%2C%20relative%20url()%20references%20inside%20imported%20Sass/Less%20files%20that%20are%20in%20different%20directories%20from%20the%20root%20file%20are%20also%20automatically%20rebased%20to%20ensure%20correctness.) and break the app?