Giter Site home page Giter Site logo

gulp-css-url-rebase's Introduction

gulp-css-url-rebase Build Status Dependency Status

Rebase relative image URLs

This project has been forked to fix issues that were not resolved by its original author.

Install

npm install gulp-css-url-rebase --save-dev

Example

var gulp = require('gulp');
var rebase = require('gulp-css-url-rebase');

gulp.task('default', function () {
  gulp.src('css/**/*.css')
    .pipe(rebase())
     .pipe(concat('style.css'))
     .pipe(gulp.dest('./build/'));
});

rebase urls and copy files

var gulp = require('gulp');
var rebase = require('gulp-css-url-rebase');

gulp.task('default', function () {
  gulp.src(['css/**/*.css',
            'plugins/font-awesome/css/font-awesome.min.css',
            'plugins/bootstrap/css/bootstrap.min.css'])
    .pipe(rebase({
        copyFiles:{
            //urls in css will be rebased relative to publicPath
            publicPath: "./assets",
            //where to copy the files
            filePath: './build/assets/',
            fileTypes: [
                {
                    //match file extensions
                    test: /\.(png|jpg|gif)$/,
                    //subfolder relative to filePath
                    folder: 'img',
                    //max file size for data uri in kb
                    inlineLimit: 100
                },
                {
                    test: /\.(woff|woff2|eot|ttf|svg)(\?.*?|)$/,
                    folder: 'font'
                }
            ]
        }    
    }))
     .pipe(concat('style.css'))
     .pipe(gulp.dest('./build/'));
});

What it tries to solve

Let's say you have this structure:

bower_components
├ dep1
│   ├ images/*
│   └ css/
│       └ style.css
├ dep2
│   ├ images/*
│   └ css/
│       └ style.css
dist/

In dep1/css/style.css you might have:

.sel {
  background: url('../images/icons/home.png') no-repeat top left;
}

And in dep2/css/style.css:

.item {
  background: url('../images/logo.jpg') no-repeat top left;
}

When I minify everything, for example to be in dist/style.css in production. I want this final file for the css above, and all the files are copied to dist/assets/img/, so I don't bother with all the urls in css

.sel {
  background: url('dist/assets/img/icons/home.jpg') no-repeat top left;
}
.item {
  background: url('dist/assets/img/logo.jpg') no-repeat top left;
}

gulp-css-url-rebase's People

Contributors

balthazar avatar gitawego avatar kimjoar avatar

Watchers

 avatar

Forkers

amustaine

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.