gulp-inline-source icon indicating copy to clipboard operation
gulp-inline-source copied to clipboard

Support for rewriting CSS-URLs

Open thasmo opened this issue 8 years ago • 5 comments

It would be awesome if urls in stylesheets would be rewritten when embedded.

.div {
  background: url('../images/background.jpg');
}

should become

.div {
  background: url('static/images/background.jpg');
}

This probably needs a new config option to define the path to use for rewriting.

thasmo avatar Oct 21 '15 16:10 thasmo

+1

Bogdaan avatar Nov 02 '15 18:11 Bogdaan

+1 I can't use this plugin without this functionality, please consider it!

dbkaplun avatar Nov 21 '15 16:11 dbkaplun

https://github.com/popeindustries/inline-source/issues/30 I've added a new issue to the original plugin for this and am willing to write it, I will post any updates here :+1:

alexnewmannn avatar Jan 20 '16 02:01 alexnewmannn

You can make your own stream by using gulp-rework with rework-plugin-url :)

like this (note that script is written in coffeescript):

$.rebaseCSSUrl = $.lazypipe()
  .pipe () ->
    return $.rework $.reworkUrl (url) ->
      return url if url.match /^data:/i # keep url if url is Data URI
      return url if url.match /^http/i # keep url if url is Full URL
      return url if url.match /^\// # keep url if url is absolute path

      # remove all of parent path references
      # and prepend asset path
      return '/assets/bower-assets/' + $.path.basename url

After creating your own stream, just pipe it before inline-source stream.

mooyoul avatar May 23 '16 07:05 mooyoul

@fmal Answered :)

mooyoul avatar May 23 '16 07:05 mooyoul