V
V
vasIvas2015-10-05 18:00:37
JavaScript
vasIvas, 2015-10-05 18:00:37

How to dynamically change paths in gulp?

src/
    a-module/
            css/
            js/
            html/
            sass/
            ts/
            jade/
    b-module/
            css/
            js/
            html/
            sass/
            ts/
            jade/

Is it possible to set dynamic paths during compilation so that preprocessors from module "a" compile to module "a", and from "b" to "b"?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
yaroslavgrishajev, 2015-10-15
@vasIvas

If I'm not mistaken, it's enough just to specify a path like 'src/**/*.*'
Revised the question :) The gulp-rename
plugin does what you need. It is described in the documentation there: you can change the path specified in gulp.src on the fly (for example, replace sass with css). For me it looked like this:

var gulp = require('gulp'),
    sass = require('gulp-sass'),
    rename = require('gulp-rename');

gulp.task('sass', function () {
    gulp.src('./src/**/*.scss') 
        .pipe(sass({
            includePaths: ['./src/']
        }))
        .pipe(rename(function(path){

                // path.dirname = 'module-a(b)/sass' - это то, что задано в gulp.src
        	path.dirname = path.dirname.replace( "sass", "css" );

                // path.dirname = 'module-a(b)/css' - а теперь мы поменяли так, как нам нужно
        	return path; 
      }))
        .pipe(gulp.dest('./src/')); // и тогда все сложится в src/module-a(b)/css - в нужную папку модуля
});

gulp.task('default', ['sass']);

But there you can dance to your heart's content.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question