postcss / postcss-url

PostCSS plugin to rebase url(), inline or copy asset.
MIT License
377 stars 59 forks source link

inline and resolve #104

Closed Diokuz closed 6 years ago

Diokuz commented 7 years ago

I want to inline all files under 4 kb and resolve all others. How can I do that?

I mean this one

.cls1 {
  background-image: url('small-image.png');
}
.cls2 {
  background-image: url('big-image.png');
}

should transform to

.cls1 {
  background-image: url('base64...');
}
.cls2 {
  background-image: url('/Users/.../project/src/images/big-image.png');
}

My options object looks like

{
  url: 'inline',
  maxSize: 4,
  fallback: 'rebase'
}

But nothing happens for big files.

sergcen commented 7 years ago

Currently rebase for fallback not supported, you can set as fallback copy or custom function. I will add support rebase in next release.

Diokuz commented 7 years ago

My workaround here:

  require('postcss-url')({ url: 'inline', maxSize: 4 }),
  // @todo remove second `postcss-url` after https://github.com/postcss/postcss-url/issues/104
  require('postcss-url')({ url: 'rebase', to: './src' }),

:)

sergcen commented 7 years ago

done 7.1.0