Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Rebase relative image URLs

NotificationsYou must be signed in to change notification settings

chrisladams/gulp-css-rebase-urls

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gulp-css-rebase-urls

Rebase relative image URLs

This is still a work in progress

Install

Install with npm

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

Example

vargulp=require('gulp');varrebaseUrls=require('gulp-css-rebase-urls');gulp.task('default',function(){gulp.src('css/**/*.css').pipe(rebaseUrls()).pipe(concat('style.css'))// <-- just an example.pipe(gulp.dest('./build/'));});

What it tries to solve

Let's say you have this structure:

.|-- css|   |-- some|   |   `-- deep|   |       |-- path|   |       |   `-- style.css|   |       `-- style.css|   `-- style.css`-- img    |-- a.jpg    |-- b.jpg    `-- deeper        `-- c.jpg

Incss/style.css you might have:

.sel {background:url('../img/deeper/c.jpg') no-repeat top left;}

And incss/some/deep/path/style.css you might have:

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

When I minify everything, for example to be in./style.css inproduction. I want this final file for the css above:

.sel {background:url('img/deeper/c.jpg') no-repeat top left;}.item {background:url('img/a.jpg') no-repeat top left;}

Using the 'convertToAbsolute' option

This option will prefix the rebased relative URL with a forward slash to convert it into an absolute path. This is to accommodate situations where the CSS files are being transferred into another directory (such as a temp directory for generated files) but the images aren't being relocated.

By default the option is turned off.

Example

vargulp=require('gulp');varrebaseUrls=require('gulp-css-rebase-urls');gulp.task('default',function(){gulp.src('css/**/*.css').pipe(rebaseUrls({convertToAbsolute:true,})).pipe(concat('style.css'))// <-- just an example.pipe(gulp.dest('./build/'));});

Pull requests and use cases welcome.

About

Rebase relative image URLs

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript69.7%
  • CSS30.3%

[8]ページ先頭

©2009-2025 Movatter.jp