kaiqigong / gulp-cdnify

A gulp plugin that converts local URLs to CDN ones.
17 stars 9 forks source link

Ability to configure different different CDN base based on asset extensions #1

Closed elisechant closed 9 years ago

elisechant commented 9 years ago

It would be useful if gulp-cdnify supported different CDN hosts for different asset extensions. For example, assets with font extensions and image assets. Something like:

cdnify({
  base: 'http://mycdn.com/',
  negate: {
    '/eot]ttf|woff|woff2/$': 'http://myfontcdn.com/'
  }
});
kaiqigong commented 9 years ago

Sorry for late response, actually, there is a powerful method allowing us to do this.

rewrite: function(url, process) {
  return "whatever you want";
}

The url is the path extracted from src, the process is the default convert function. Sample usage:

pipe($.cdnify({
  rewriter: function(url, process) {
    if (/eot]ttf|woff|woff2/.test(url)) {
      return 'http://myfontcdn.com/' + url;
    } else if (/(png|jpg|gif)$/.test(url)) {
      return 'http://myimagecdn.com/' + url;
    } else {
      return process(url);
    }
  }
}));