Как игнорировать файл с помощью gulp?

У меня есть следующая структура папок и файлов:

Vendor   
  bootstrap
    css
      -bootstrap.css
    js
      -bootstrap.js   
  font-awesome
    css
      -font-awesome.css   
  nivo-slider
    -nivo-slider.css   
  theme
    -theme.css
    -theme-animate.css
    -theme-blog.css
    -theme-responsive.css
    -theme-shop.css


Я пытаюсь убедиться, что файлы css добавляются в поток именно в таком порядке:

1) Файл bootstrap.css
src/vendor/bootstrap/css/bootstrap.css

2) Все остальные файлы css внутри подкаталогов 'src/vendor/' в произвольном порядке (в будущем я добавлю больше, поэтому не хочу делать это слишком конкретным)
src/vendor/font-awesome/css/font-awesome.css
src/vendor/nivo-slider/nivo-slider.css

3) Эти определенные файлы css внутри каталога 'src/vendor/theme/' в произвольном порядке
src/vendor/theme/theme.css
src/vendor/theme /theme-animate.css
src/vendor/theme/theme-blog.css
src/vendor/theme/theme-shop.css

4) И, наконец, файл theme-responsive.css
src/vendor/theme/theme-responsive.css

Вот моя попытка:

var gulp = require('gulp');
var streamqueue = require('streamqueue');

gulp.task('styles', function() {
    var stream = streamqueue({ objectMode: true });

    // file that needs to be at the beginning of the concatenated css file
    stream.queue(
        gulp.src('src/vendor/**/bootstrap.css')
    );

    //Now I want to add most of the remaining files, except for the bootstrap.css file that was already added as well as any files with the word theme at the beginning of it
    stream.queue(
        gulp.src('src/vendor/**/*.css', '!src/vendor/**/bootstrap.css', '!src/vendor/**/theme*.css')
    );

    //Now I would like to add the files that begin with the word theme at the beginning, except for theme-responsive.css
    stream.queue(
        gulp.src('src/vendor/theme/**/*.css', '!src/vendor/theme/theme-responsive.css')
    );

    //Now I would like to add the theme-responsive.css file
    stream.queue(
        gulp.src('src/vendor/theme/theme-responsive.css')
    ); 

    return stream.done()
        .pipe(concat("app.css"))
        .pipe(gulp.dest('public/css/'))
});

К сожалению, когда я сейчас запускаю этот скрипт, bootstrap.css и другие файлы, которые он должен игнорировать, добавляются несколько раз. Как игнорировать файл с помощью gulp?


person zeckdude    schedule 12.09.2014    source источник
comment
Нижняя часть этого ответа должна вам помочь.   -  person chconger    schedule 13.09.2014
comment
В противном случае, является ли мой подход хорошим способом достижения того, что я пытаюсь сделать?   -  person zeckdude    schedule 13.09.2014


Ответы (2)


Вы почти у цели, восклицательный знак для него '!', просто нужно передать его как массив:

eg:

stream.queue(
  gulp.src([
    'src/vendor/theme/**/*.css',
    '!src/vendor/theme/theme-responsive.css'
  ]);
);

Для получения дополнительной информации: http://jb.demonte.fr/blog/production-package-with-gulp-js/

Надеюсь это поможет.

person felipekm    schedule 13.09.2014

Попробуйте использовать gulp-concat. Файлы будут объединены в том порядке, в котором они указаны в функции gulp.src. https://www.npmjs.org/package/gulp-concat

var concat = require('gulp-concat');

gulp.task('scripts', function() {
    gulp.src(['src/vendor/bootstrap/**/*.css', 
              'src/vendor/font-awesome/**/*.css', 
              'src/vendor/nivo-slider/**/*.css', 
              'src/vendor/theme/theme.css',
              'src/vendor/theme/theme-animate.css',
              'src/vendor/theme/theme-blog.css',
              'src/vendor/theme/theme-shop.css',
              'src/vendor/theme/theme-responsive.css'])
        .pipe(concat('app.css'))
        .pipe(gulp.dest('public/css/'))
    ;
});
person Doodlebot    schedule 13.09.2014