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

Does not rewrite url in @import

Open ikorolev93 opened this issue 6 years ago • 4 comments

None of the basic examples in the readme work for @import url(...) constructions, they just stay the same.

ikorolev93 avatar Oct 25 '18 12:10 ikorolev93

Can you share your webpack config?

bahtou avatar Apr 02 '19 23:04 bahtou

I also see the same issue, for example run this snippet and see that the process function is never called.

function process({url}) {
  console.log('never called !!')
  return url;
}

await postcss()
        .use(url({url: process}))
        .process("@import 'some.css';", {from: undefined});

danielschwartz85 avatar May 31 '19 10:05 danielschwartz85

I don't have much context but I was also facing similar problem in my Gatsby project. The @import url(...) on top of css is parsed by postcss-import and you need to write custom resolve function to change them

https://github.com/postcss/postcss-import#resolve

Something like this - https://github.com/postcss/postcss-import/issues/190#issuecomment-298078092

ankurparihar avatar Aug 12 '21 06:08 ankurparihar

Rewriting url() inside imported files works if postcss-url plugin with proper config is added to the plugins field of the postcss-import plugin config:

const postCssUrl = require("postcss-url")({
  // config here
});

module.exports = {
  plugins: [
    require("postcss-import")({
      plugins: [postCssUrl],
    }),
    postCssUrl,
  ],
};

shishkin avatar Aug 15 '22 19:08 shishkin