I'm having trouble with a glob and gulp.dest(). My task looks like this
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'));
}));
If my path for example was ./clients/my-client/assets/less/style.less
the path ends up being `./clients/my-client/assets/css/my-client/assets/less/css I tried using a rename function like
.pipe(rename(function (path) {
path.dirname = '';
}))
Before but all that did was put the file at ./clients/css/style.css
The desired directory should be ./clients/my-client/assets/less/style.css
and thought this would all be rather easy, and perhaps it is, but I'm really struggling. Any help would be really appreciated!
I feel like this isn't a great solution, considering how it could theoretically go wrong, but it worked for me for now.
I used gulp-rename
to simply replace less
for css
in the dirname
.
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}) );
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.