以下是我正在使用的代码以及我正在考虑解决方案的方式。
gulp.task('templates:components', function () {
log('Building components..');
//if (filename === 'app.jade') {
// return gulp.src().....
// } else
return gulp.src(source.templates.components)
.pipe($.if(!isProduction, $.changed(build.templates.views, {extension: '.html'})))
.pipe($.jade())
.on('error', handleError)
.pipe($.htmlPrettify(prettifyOpts))
.pipe(flatten({ includeParents: 1} ))
.pipe(gulp.dest(build.templates.views + 'views'));
});
我不确定如何设置我的逻辑来检测文件,我已经搜索但是无法找到明确的示例或插件来执行此操作。
如何根据文件名确定目的地的结果?
答案 0 :(得分:0)
我用gulp-flatten挑选出我想要的路径部分。
var source = {
scripts: [paths.scripts + 'app.module.js',
// template modules
paths.scripts + 'modules/**/*.module.js',
paths.scripts + 'modules/**/**/*.js',
// custom modules
paths.scripts + 'components/**/*.module.js',
paths.scripts + 'components/**/*.js'
],
templates: {
components: [paths.components + '**/views/**/*.jade', paths.components + '**/**/**/*.jade']
},
styles: {
app: [paths.styles + '*.*'],
themes: [paths.styles + 'themes/*'],
watch: [paths.styles + '**/*', '!' + paths.styles + 'themes/*']
},
images: paths.images
};
// BUILD TARGET CONFIG
var build = {
scripts: paths.app + 'js',
styles: paths.app + 'css',
templates: {
index: '../',
views: paths.app,
cache: paths.app + 'js/' + 'templates.js',
},
images: paths.app + 'img'
};
gulp.task('templates:components', function () {
log('Building components..');
return gulp.src(source.templates.components)
.pipe($.if(!isProduction, $.changed(build.templates.views, {extension: '.html'})))
.pipe($.jade())
.on('error', handleError)
.pipe($.htmlPrettify(prettifyOpts))
.pipe(flatten({ includeParents: 1} ))
.pipe(gulp.dest(build.templates.views + 'views'));
});