我在 glob 和 gulp.dest(( 上遇到了问题。我的任务如下所示
return gulp.src('./clients/*/assets/less/*.less',{ base: process.cwd() })
.pipe(less({
paths:[path.join(__dirname, 'less')]
}).on('error', function(err){
gutil.log(err);
this.emit('end');
}))
.pipe(autoprefixer({
browsers: ['last 2 versions'],
cascade: false
}))
.pipe(gulp.dest(function(file){
return path.normalize(path.join(file.path, '../css'));
}));
例如,如果我的路径是./clients/my-client/assets/less/style.less
则路径最终是"./clients/my-client/assets/css/my-client/assets/less/css 我尝试使用重命名函数,例如
.pipe(rename(function (path) {
path.dirname = '';
}))
以前,但所做的只是将文件放在./clients/css/style.css
所需的目录应该是./clients/my-client/assets/less/style.css
的,并认为这一切都会相当容易,也许确实如此,但我真的很挣扎。任何帮助将不胜感激!
考虑到理论上它是如何出错的,我觉得这不是一个很好的解决方案,但它现在对我有用。
我用gulp-rename
简单地将less
替换为dirname
中的css
.
var src = './clients/*/assets/less/*.less';
return gulp.src(src,{base: './clients/'})
.pipe(plumber())
.pipe(sourcemaps.init())
.pipe(less({
paths:[path.join(__dirname, 'less')]
}).on('error', function(err){
gutil.log(err);
this.emit('end');
}))
.pipe(cleanCSS({debug: true}, function(details) {
console.log(details.name + ': ' + details.stats.originalSize);
console.log(details.name + ': ' + details.stats.minifiedSize);
}))
.pipe(filesize())
.pipe(rename(function (path) {
path.dirname = path.dirname.replace(/less/i,'css');
}))
.pipe(gulp.dest('./clients/'))
.pipe(notify({ message: "Style compressed", onLast: true}) );