1. gulp-modify-css-urls
Gulp plugin for modifying CSS URLs
gulp-modify-css-urls
Package: gulp-modify-css-urls
Created by: dustinspecker
Last modified: Sat, 18 Jun 2022 17:33:23 GMT
Version: 2.0.0
License: MIT
Downloads: 11,070
Repository: https://github.com/dustinspecker/gulp-modify-css-urls

Install

npm install gulp-modify-css-urls
yarn add gulp-modify-css-urls

gulp-modify-css-urls

NPM version
Build Status
Coverage Status

Dependencies
DevDependencies
PeerDependencies

PRs Welcome
Commitizen friendly
semantic-release

Gulp plugin for modifying CSS URLs

Install

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

Usage

ES2015

 /* gulpfile.babel.js */
import gulp from 'gulp';
import modifyCssUrls from 'gulp-modify-css-urls';

/* style.css
body {
  background-image: url('images/logo.png');
}
*/
gulp.task('modifyUrls', () =>
  gulp.src('style.css')
    .pipe(modifyCssUrls({
      modify(url, filePath) {
        return `app/${url}`;
      },
      prepend: 'https://fancycdn.com/',
      append: '?cache-buster'
    }))
    .pipe(gulp.dest('./'))
);
/* style.css
body {
  background-image: url('https://fancycdn.com/app/images/logo.png?cache-buster');
}
*/

ES5

 /* gulpfile.js */
var gulp = require('gulp')
  , modifyCssUrls = require('gulp-modify-css-urls');

/* style.css
body {
  background-image: url('images/logo.png');
}
*/
gulp.task('modifyUrls', function () {
  return gulp.src('style.css')
    .pipe(modifyCssUrls({
      modify: function (url, filePath) {
        return 'app/' + url;
      },
      prepend: 'https://fancycdn.com/',
      append: '?cache-buster'
    }))
    .pipe(gulp.dest('./'));
});
/* style.css
body {
  background-image: url('https://fancycdn.com/app/images/logo.png?cache-buster');
}
*/

Options

modify

A function that is passed the current URL and file path and then returns the modified URL to replace the existent URL.

The modify function is always ran before append and prepend options.

append

A string that is appended to every URL.

prepend

A string that is prepended to every URL.

License

MIT

RELATED POST

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin