Anidetrix / rollup-plugin-styles

🎨 Universal Rollup plugin for styles: PostCSS, Sass, Less, Stylus and more.
https://anidetrix.github.io/rollup-plugin-styles
MIT License
242 stars 43 forks source link

Duplicate emitted files when multiple `url()` references to same file #170

Open taylor-hunt-kr opened 3 years ago

taylor-hunt-kr commented 3 years ago

Some CSS like this:

.thing {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background-image: url("./img/wire.png"), url("./img/wire.png");
  background-repeat: no-repeat, no-repeat;
  background-position: 33% 0, 66% 0;
  background-size: 11px 56px, 11px 56px;
}

…produces the following Rollup warning:

(!) The emitted file "wire-9d64d534.png" overwrites a previously emitted file of the same name.

While nothing breaks, processing url() assets only once each seems like a good possible improvement.

taylor-hunt-kr commented 3 years ago

I was able to fix the warning by moving a seemingly-unrelated chunk of code, so if you find that you cannot reproduce this bug, then that means I mistakenly assumed it was a bug in rollup-plugin-styles. Sorry about that!

taylor-hunt-kr commented 3 years ago

Whoop, spoke too soon; it appears to be somewhat non-deterministic.

taylor-hunt-kr commented 3 years ago

I forgot to show my plugin config, sorry about that:

stylesPlugin({
  mode: 'extract',
  sourceMap: true,
  minimize: __PROD__,
  url: {
    publicPath,
    hash: '[hash].[ext]'
  }
})