var gulp = require('gulp'); var RevAll = require('gulp-rev-all'); var uglify = require('gulp-uglify'); var filter = require('gulp-filter'); var csso = require('gulp-csso'); var useref = require('gulp-useref'); gulp.task('default', function () { var jsFilter = filter("**/*.js"); var cssFilter = filter("**/*.css"); var htmlFilter = filter('**/*.html'); var assets = useref.assets(); var revAll = new RevAll({ //不重命名文件 dontRenameFile: ['.html'] , //無需關聯處理文件 dontGlobal: [ /^\/favicon.ico$/ ,'.bat','.txt'], //該項配置隻影響絕對路徑的資源 prefix: 'http://s0.static.server.com' }); return gulp.src(['staticPreprocessing/src/**']) //合併html裏面的js/css .pipe(htmlFilter) .pipe(assets) .pipe(assets.restore()) .pipe(useref()) .pipe(htmlFilter.restore()) //壓縮js .pipe(jsFilter) .pipe(uglify()) .pipe(jsFilter.restore()) //壓縮css .pipe(cssFilter) .pipe(csso()) .pipe(cssFilter.restore()) //加MD5後綴 .pipe(revAll.revision()) //輸出 .pipe(gulp.dest('staticPreprocessing/dist')) //生成映射json文件 .pipe(revAll.manifestFile()) .pipe(gulp.dest('staticPreprocessing/dist')); }); gulp.task('watch', function () { gulp.watch('staticPreprocessing/src/**', ['default']); });