Gulp忽略输入文件

时间:2016-12-02 17:07:45

标签: gulp output

这是我的gulpfile:

// including plugins
var gulp = require('gulp')
, rename = require('gulp-rename')
, uglify = require("gulp-uglify")
, cssmin = require("gulp-cssmin");

// task css
gulp.task('minify-css', function () {
    gulp.src([
        './www/assets/css/bootstrap.min.css',
        './www/assets/css/admin.css',
        '!./www/assets/css/build.min.css'
    ])
    .pipe(cssmin())
    .pipe(rename('build.min.css'))
    .pipe(gulp.dest('./www/assets/css'));
});

// task js
gulp.task('minify-js', function () {
    gulp.src([
        './www/assets/js/jquery.min.js',
        './www/assets/js/boostrap.min.js',
        './www/assets/js/vue.min.js',
        './www/assets/js/vue-resource.min.js',
        './www/assets/js/MiniModel.js',
        './www/assets/js/AdminUsers.js',
        '!./www/assets/js/build.min.js'
    ])
    .pipe(uglify())
    .pipe(rename('build.min.js'))
    .pipe(gulp.dest('./www/assets/js'));
});

gulp.task('default', ['minify-css', 'minify-js']);

运行./node_modules/.bin/gulp后输出为:

  1. build.css只有admin.css
  2. build.js只有AdminUsers.js
  3. 为什么在输出中遗漏了很多源文件?

    更多细节: Ubuntu:14.10 节点版本:v0.10.25 Gulp版本:3.9.1

    UPDATE1 :我在index.html中使用如下:

    <script type="text/javascript" src="/mini-vue/www/assets/js/build.min.js"></script>
    <script type="text/javascript">
        var usersmodel = new MiniModel(Vue, 'users', '/mini-vue/www/');
        var adminusers = new AdminUsers(Vue, usersmodel);
        adminusers.reload(1);
    </script>
    

1 个答案:

答案 0 :(得分:0)

尝试使用此

var minifyCSS = require('gulp-minify-css'),
    minifyJS = require('gulp-minify'),
    concat = require('gulp-concat'),
    uglify = require('gulp-uglify'),

gulp.task('minify-js', function() {
  return gulp.src('./www/assets/js/**/*.js')
    .pipe(minifyJS())
    .pipe(concat('build.min.js'))
    .pipe(uglify({ mangle: false }))
    .pipe(gulp.dest('./www/assets/js'));
});

gulp.task('minify-css', function() {
  return gulp.src('./www/assets/css/**/*.css')
    .pipe(minifyCSS())
    .pipe(concat('build.min.css'))
    .pipe(gulp.dest('./www/assets/css'));
});

gulp.task('default', ['minify-css', 'minify-js']);