bholloway / resolve-url-loader

Webpack loader that resolves relative paths in url() statements based on the original source file
563 stars 71 forks source link

Proposal: refactor the loader as a postcss plugin #196

Open yfwz100 opened 3 years ago

yfwz100 commented 3 years ago

I switch from webpack to vite/rollup and miss the counterpart of this plugin in vite/rollup. Don't know if it's possible to publish a plugin for postcss or rollup as well?

bholloway commented 3 years ago

Its plausible that the algorithm could be done just in postcss but as far as I can tell it would need to be the first plugin so that it could use the incoming source-map. Its not a trivial change though, particularly if we want to have test coverage.

This proposal would need a substantial number of upvotes. Please 👍 to add your vote.

yfwz100 commented 3 years ago

I found a stupid way to overcome this issue: compile scss to css via webpack & this plugin first and then feed the css to vite, which can perfectly rebase relative paths.

bholloway commented 3 years ago

Not ideal but good that you are unblocked @yfwz100.

bholloway commented 3 years ago

Looks like @paraofheaven has already tried a simple conversion with postcss-resolve-url on npm.

@paraofheaven I don't see much usage is this currently working?

yfwz100 commented 3 years ago

It seems that it's not active any more. I'll try it later.

Pong420 commented 10 months ago

The package postcss-resolve-url cannot be used, it looks like a copy from Next.js

https://github.com/vercel/next.js/blob/canary/packages/next/src/build/webpack/loaders/resolve-url-loader/lib/postcss.ts#L58-L100