Answer the question
In order to leave comments, you need to log in
How to generate css to the right directory (gulp)?
The problem is that the gallpfile is very far from the sass files, and the css is generated relative to the gallpfile,
how can I make them be generated in the css folder one directory higher than the sass file?
here is my galp file:
var path = require("path");
var gulp = require('gulp'),
sass = require('gulp-sass'),
rename = require("gulp-rename"),
flatten = require('gulp-flatten'),
plumber = require('gulp- plumber'),
gutil = require('gulp-util');
var onError = function (err) {
gutil.beep();
console log(err);
};
gulp.task('sass', function () {
gulp.src('**/sass/*.scss')
.pipe(plumber({errorHandler: onError}))
.pipe(sass())
.pipe(flatten({includeParents: 0}))
.pipe(gulp.dest(function (file) {
var dir = path.dirname( file.path).split('/scss')
return dir[1] ? path.join(dir[0], 'css', dir[1]) : path.join(dir[0], 'css') ;
}))
});
gulp.task('watch', function () {
gulp.watch('**/sass/*.scss', ['sass']);
});
//
Tried again with this hapfile
var path = require("path");
var gulp = require('gulp'),
sass = require('gulp-sass'),
debug = require('gulp-debug'),
var onError = function (err) {
gutil.beep();
console.log(err);
};
gulp.task('sass', function () {
gulp.src('**/sass/*.scss' , {cwd: __dirname} )
.pipe(plumber({errorHandler: onError}))
.pipe(sass())
.pipe(debug({title: 'unicorn:'}))
.pipe(gulp.dest('../css', {cwd: __dirname}))
});
gulp.task('watch', function () {
gulp.watch('**/sass/*.scss', ['sass']);
});
Answer the question
In order to leave comments, you need to log in
There is no time to test, but I do not think that there will be problems.
var path = require('path'),
gulp = require('gulp'),
sass = require('gulp-sass'),
rename = require('gulp-rename');
gulp.task('sass', function () {
return gulp.src('**/sass/*.scss')
.pipe(sass())
.pipe(rename(function (filePath) {
filePath.dirname = path.join(filePath.dirname, '../css/');
return filePath;
}))
.pipe(gulp.dest('./'));
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question