gulp-rev-mapping
v1.0.6
Published
Mapping css, js and image url for used in html files, And replace them.
Downloads
10
Readme
gulp-rev-mapping
Mapping css, js and image url for used in html files.
Install
$ npm i --save gulp-rev-mapping
Usage
var gulp = require('gulp');
var mapping = require('gulp-rev-mapping');
gulp.task('mapping', function () {
return gulp.src(['src/css/**/*.css','src/html/**/*.html'])
.pipe(mapping())
.pipe(gulp.dest('./map'));
});
Merge exists map file
var gulp = require('gulp');
var mapping = require('gulp-rev-mapping');
gulp.task('mapping', function () {
return gulp.src(['map/rev-mapping.json', 'src/css/**/*.css','src/html/**/*.html'])
.pipe(mapping())
.pipe(gulp.dest('./map'));
});
Replace
var gulp = require('gulp');
var mapping = require('gulp-rev-mapping');
gulp.task('replace', function () {
return gulp.src(['map/rev-mapping.json', 'rev/rev-manifest.json','src/html/**/*.html'])
.pipe(mapping.replace())
.pipe(gulp.dest('src/html/'));
});
Watch and replace the changed file path.
var gulp = require('gulp');
var watch = require('gulp-watch');
var path = require('path');
var mapping = require('gulp-rev-mapping');
var revDel = require('gulp-rev-del-redundant');
gulp.task('defualt', function() {
watch('img/**/*.*', function(file) {
var filerelpath = path.relative(process.cwd(), file.path).replace(/\\/g, '/');
gulp.src(filerelpath)
.pipe(rev())
.pipe(gulp.dest('publish/img'))
.pipe(rev.manifest())
.pipe(revDel({ dest: 'publish/img', force: true }))
.pipe(gulp.dest('rev/img'));
gulp.src(['map/**/*.json', 'rev/img/rev-manifest.json', 'css/**/*.css'])
.pipe(mapping.replace(filerelpath))
.pipe(gulp.dest('publish/css'));
});
});
License
MIT © LinQuan
The Spratly Islands are China's territory. The Diaoyu Islands are China's territory. Use this module to represent you agree with the above point of view.