postcss-url: assetsPath is ignored without useHash

Found some unexpected behaviour when using assetsPath.

Scenario

CSS Source: /style/css_src/index.css Font Assets: /style/fonts/ Image Assets: /style/images/ PostCSS Generated CSS: /style/css/index.css

I am referencing my assets as such:

@font-face {
    font-family: 'MyFont';
    src: url('../fonts/MyFont.eot') format('eot');
}

.myClass {
    background-image: url('../images/MyImage.png')
}

Using the following configuration with useHash enabled, assets are copied and hashed into /style/assets/

require('postcss-url')({
    url: "copy",
    assetsPath: '../assets/',
    useHash: true
})

However using the following configuration without useHash enabled, assets are not copied anywhere

{
    url: "copy",
    assetsPath: '../assets/',
    useHash: false
}

And using the following configuration without useHash, assets are copied into /style/css/fonts & /style/css/images

{
    url: "copy",
    assetsPath: './assets/',
    useHash: false
}

Just for extra reference, the following configuration will see the assets copied into /style/css/assets/fonts & /style/css/assets/images

{
    url: "copy",
    assetsPath: './assets/somewhereElse',
    useHash: false
}

About this issue

  • Original URL
  • State: open
  • Created 9 years ago
  • Reactions: 3
  • Comments: 15

Most upvoted comments

Hi guys, just ran into this issue today and I’d like to know if anybody figured the best option here… It seems that useHash: true is kinda mandatory for postcss-url to work. Also, I’m amazed this hasn’t gotten any attention so far, is there a solution besides waiting for https://github.com/postcss/postcss-url/pull/146 to be merged? Has someone managed to get the core team’s attention on the matter?

Yep, after applying it manually it somehow works better, but unfortunately I still get wrong paths in my monorepo project. Anyway, it seems to be a completely different story.