2014-09-12 94 views
0

我有以下文件夹和文件结构:如何使用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)自举。 CSS文件
SRC /供应商/引导/ CSS/bootstrap.css

2)所有其他CSS文件的我在'src/vendor /'子目录中没有特别的顺序(我将在未来添加更多,所以我不想这样做太具体)
src/vendor/font-awesome/css/font没有特定的顺序
SRC -awesome.css
SRC /供应商/ NIVO滑块/ NIVO-slider.css

3)的内部,这些特定的CSS文件 'SRC /供应商/主题/' 目录/vendor/theme/theme.css
src/vendor/theme/theme-animate.css
src/vendor/theme/theme-blog.css
SRC /供应商/主题/主题shop.css

4)最后的主题responsive.css文件
SRC /供应商/主题/主题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和其他文件,它应该被忽略的是一个dded多次。如何使用gulp忽略文件?

+1

底部的这个答案应该可以帮到你.http://stackoverflow.com/a/22413078/4014432 – chconger 2014-09-13 00:05:48

+0

否则,我的方法是实现我想要做的一个好方法吗? – zeckdude 2014-09-13 00:08:23

回答

1

尝试使用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/')) 
    ; 
});