Gulp useref uglify()不会缩小js文件,它只能进行串联。
预期结果将所有文件连接到一个文件并缩小文件。
<!-- build:css css/combined.css -->
<link rel="stylesheet" href="css/style1.css" type="text/css">
<link rel="stylesheet" href="css/style2.css" type="text/css">
<link rel="stylesheet" href="css/style3.css" type="text/css">
<!-- endbuild -->
<!-- build:js scripts/combinedlib.js -->
<script src="js/script1.js"></script>
<script src="js/script2.js"></script>
<script src="js/script3.js"></script>
<script src="js/script4.js"></script>
<!-- endbuild -->
<!-- build:js scripts/app.js -->
<script src="scripts/app.js"></script>
<!-- endbuild -->
<!-- build:js scripts/config.js -->
<script src="config/config1.js"></script>
<script src="config/config2.js"></script>
<script src="config/config3.js"></script>
<script src="config/config4.js"></script>
<!-- endbuild -->
<!-- build:js scripts/common.js -->
<script src="config/common1.js"></script>
<script src="config/common2.js"></script>
<script src="config/common3.js"></script>
<script src="config/common4.js"></script>
<!-- endbuild -->
预期结果:以下所有文件都必须缩小。 组合lib.js,app.js,config.js,common.js
我的Gulp文件
var gulp = require('gulp'),
useref = require('gulp-useref'),
gulpif = require('gulp-if'),
del = require('del');
uglify = require('gulp-uglify'),
minifyCss = require('gulp-clean-css'),
replace = require('gulp-replace'),
rename = require('gulp-rename');
gulp.task('clean', function () {
return del('dist/');
});
gulp.task('buildapp', function () {
gulp.src("app/images/**/*.*")
.pipe(gulp.dest('dist/images/'));
gulp.src("app/css/fonts/*.*")
.pipe(gulp.dest('dist/fonts/'));
gulp.src("app/modules/**/*.html")
.pipe(gulp.dest('dist/modules/'));
gulp.src("app/modules/**/*.json")
.pipe(gulp.dest('dist/modules/'));
return gulp.src('app/index.html')
.pipe(useref())
.pipe(gulpif('app/**/*.js', uglify()))
.pipe(gulpif('app/assets/**/*.css', minifyCss()))
.pipe(gulpif("app/images/**/*.*",gulp.dest('dist/images') ))
.pipe(gulp.dest('dist'));
});
gulp.task('default', gulp.series('clean','buildapp'));