文件夹结构:
project
|
+-coffee
| |
| +-main.coffee
| |
| +-testDir
| | |
| | +-models.coffee
| | |
| | +-views.coffee
| |
| +-anotherDir
| | |
| | +-routes.coffee
| | |
| | +-views.coffee
| | |
| | +-modules.coffee
| |
| +- etc...
|
+-www
这个想法是保持文件夹结构coffee/
写入文件时的目录www/
目录。可以有任意数量的子文件夹coffee/
. All .coffee
每个文件夹中的文件应连接成一个modules.js
file:
www
|
+-modules.js
|
+-testDir
| |
| +-modules.js
|
+-anotherDir
| |
| +-modules.js
|
+- etc...
我目前有这个任务:
gulp.task('coffee', function() {
gulp.src('./coffee/**/*.coffee', {base: './coffee/'})
.pipe(coffee({bare: true}).on('error', gutil.log))
.pipe(uglify())
// .pipe(concat('modules.js'))
.pipe(gulp.dest('./www'))
});
如果没有concat()
文件被放置到正确的子文件夹中(但它们没有连接)。随着concat()
所有文件都连接成一个modules.js
file:
www
|
+-modules.js
我怎样才能正确认识到这一点?
这是一个使用的解决方案gulp-flatmap https://www.npmjs.com/package/gulp-flatmap:
var flatmap = require('gulp-flatmap');
gulp.task('coffee', function() {
return gulp.src('./coffee/{*,}/', {base:'./coffee'})
.pipe(flatmap(function(stream, dir) {
return gulp.src(dir.path + '/*.coffee')
.pipe(coffee({bare: true}).on('error', gutil.log))
.pipe(uglify())
.pipe(concat('modules.js'))
.pipe(gulp.dest('./www/' + path.relative(dir.base, dir.path)))
}))
});
这首先将coffee/
流中的目录及其所有直接子目录。然后,每个目录都会映射到一个连接所有目录的新流.coffee
相应目录中的文件。最后为每个结果指定适当的目标文件夹modules.js
文件是通过使用确定的path.relative() https://nodejs.org/api/path.html#path_path_relative_from_to.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)