简体   繁体   English

您可以使用gulp根据文件的父文件夹将文件串联在一起吗?

[英]Can you use gulp to concatenate files together based on their parent folder?

I am trying to set up a generic frame for me to use for multiple projects. 我试图建立一个通用框架供我用于多个项目。 I am mostly trying to do this to get experience with gulp/npm and building projects. 我主要是想这样做以获得gulp / npm和构建项目的经验。

I would like to keep all distinct components separated and have gulp tasks to compile each component-folders files together 我想使所有不同的组件保持分离,并进行gulp任务以将每个组件文件夹文件一起编译

Specifically, for example... 具体来说,例如...

I would like to use these globs 我想用这些球

app/components/**/scripts/**/*.js
app/components/**/*.css

With these files 有了这些文件

app/components/about/file1.css
app/components/about/file2.css
app/components/about/scripts/file1.js
app/components/about/scripts/file1.js
app/components/home/file1.css
app/components/home/file2.css
app/components/home/scripts/file1.js
app/components/home/scripts/file1.js

and I would like to combine them into these files 我想将它们合并到这些文件中

app/components/about/scripts.js
app/components/home/scripts.js
app/assets/css/components/about_styles.css
app/assets/css/components/home_styles.css

I had found this recipe that looks like it does what I want but it seems very clunky. 我发现这个食谱看起来像我想要的,但看起来很笨拙。

Is this possible with gulp? 吞咽有可能吗? If not is there some module I can use to do this with gulp? 如果没有,我可以用gulp来做一些模块吗?

Sounds like you want to use gulp-concat 听起来像您想使用gulp-concat

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

gulp.task('aboutScripts', function() {
  return gulp.src('./app/components/about/scripts/*.js')
    .pipe(concat('scripts.js'))
    .pipe(gulp.dest('./app/components/about/'));
});

gulp.task('homeScripts', function() {
  return gulp.src('./app/components/home/scripts/*.js')
    .pipe(concat('scripts.js'))
    .pipe(gulp.dest('./app/components/home/'));
});

etc. 等等

and possibly also gulp-concat-css 也许还有gulp-concat-css

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM