gulp-auto-replace
v0.1.6
Published
Autohome Replace the path address in the CSS HTML by the control list.
Downloads
9
Readme
gulp-auto-replace
Autohome Replace the path address in the CSS HTML by the control list.
Installation
npm install gulp-auto-replace
Usage
var gulp = require('gulp');
var autoReplace = require('gulp-auto-replace');
var dataList = [{
localURL: process.cwd() + '/src/images/Rendering.jpg',
onlineURL: 'http://app2.autoimg.cn/g8/M0D/22/0D/wKgHz1Z8o0mAb481AABsDFfNEUg903.jpg'
}, {
localURL: process.cwd() + '/src/images/avsevsr.png',
onlineURL: 'http://app2.autoimg.cn/g8/M0E/18/16/wKjBz1Z8o0mADParAABJPD-j46o497.png'
}];
gulp.task('replace', function() {
return gulp.src('**/*.{html,htm,css}')
.pipe(autoReplace({list: dataList}))
.pipe(gulp.dest('./build'));
});
Options
list: 本地地址和线上地址
Type: Array
例如:
[{
localURL: '/Users/luciy/Desktop/html/init-gulp-img/src/images/Rendering.jpg',
onlineURL: 'http://app2.autoimg.cn/g8/M0D/22/0D/wKgHz1Z8o0mAb481AABsDFfNEUg903.jpg'
}, {
localURL: '/Users/luciy/Desktop/html/init-gulp-img/src/images/avsevsr.png',
onlineURL: 'http://app2.autoimg.cn/g8/M0E/18/16/wKjBz1Z8o0mADParAABJPD-j46o497.png'
}]
Example
before: test.css
body{background:url("../images/Rendering.jpg")}
after: test.css
body{background:url("http://app2.autoimg.cn/g8/M0D/22/0D/wKgHz1Z8o0mAb481AABsDFfNEUg903.jpg"}
before: test.html
<img src="src/images/avsevsr.png" />
after: test.html
<img src="http://app2.autoimg.cn/g8/M0E/18/16/wKjBz1Z8o0mADParAABJPD-j46o497.png" />