gulp-js-url-adjuster

1.0.0 • Public • Published

gulp-js-url-adjuster

Find the urls in your js files, and prepend and append strings of that url.


// example gulpfile.js
var gulp = require('gulp');
var urlAdjuster = require('gulp-js-url-adjuster');
 
var options = {
  prepend: 'http://prepend/', // prepend /foo/bar
  append: '?@MD5',// resolve the url and append the md5 of that file to the url
  root: 'test', // use the root path to resolve the file
  filter: function (url) {
    return /^\/foo/.test(url);
  } // only change the absolute url start with /foo
};
 
gulp.task('default', function () {
  gulp.src('jsfile.js')
    .pipe(urlAdjuster(options))
    .pipe(gulp.dest('./'));
});
// jsfile.js
 
var a = '/some/url.png';
var b = '/foo/bar.jpg';
var c = 'foo/bar.jpg';
function d (x, y) {
  return x + y + '/foo/some/other/url.gif';
}
// result js file
var a = '/some/url.png';
var b = 'http://prepend/foo/bar.jpg?<jpg md5 value>';
var c = 'foo/bar.jpg';
function d (x, y) {
  return x + y + 'http://prepend/foo/some/other/url.gif?<gif md5 value>';
}

Note

Todo

  • Support relative url

Readme

Keywords

none

Package Sidebar

Install

npm i gulp-js-url-adjuster

Weekly Downloads

0

Version

1.0.0

License

MIT

Last publish

Collaborators

  • bigmurry