fmal / gulp-inline-source

Inline flagged js & css sources.
MIT License
212 stars 31 forks source link

Support for rewriting CSS-URLs #22

Open thasmo opened 9 years ago

thasmo commented 9 years ago

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.

Bogdaan commented 9 years ago

+1

dbkaplun commented 9 years ago

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

alexnewmannn commented 8 years ago

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:

mooyoul commented 8 years ago

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 commented 8 years ago

@fmal Answered :)