Skip to content

gulp-css-path: 转换CSS文件中的图片路径为绝对路径或CDN路径

License

Notifications You must be signed in to change notification settings

imqianduan/gulp-css-path

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Images in the CSS file path can be converted into an absolute path, and add the CDN prefix

Install

npm install gulp-css-path --save-dev

Usage

const cssUrlToAbsolute = require('gulp-css-path');
gulp.task('CSS_build', function() {
    return gulp.src(['./src/**/*.css'])
        .pipe(cssUrlToAbsolute({
            //relative path
            root: './src',
            //cdn prefix
            cdnpath: '//img.xxx.com/dist/img/'
        }))
        .pipe(gulp.dest(DIST_PATH))
});

example

1) css

.label {
    width: 57px;
    height: 69px;
    background: url(../../common/img/label.png) center center no-repeat;
}

2) convert after

.label {
    width: 57px;
    height: 69px;
    background: url(//img.xxx.com/dist/img/help/label/common/img/label.png) center center no-repeat;
}

License

New BSD and MIT. Check the LICENSE file for all the details.

About

gulp-css-path: 转换CSS文件中的图片路径为绝对路径或CDN路径

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published