There are files that have paths like:

src/component/assets/styles/**/*.css src/component/assets/scripts/**/*.js src/lib/component/assets/styles/**/*.css src/lib/component/assets/scripts/**/*.js 

In this case, the component can have any name.

You need to build everything with Gulp, replacing assets with assets-build :

 src/component/assets-build/styles/**/*.css src/component/assets-build/scripts/**/*.js src/lib/component/assets-build/styles/**/*.css src/lib/component/assets-build/scripts/**/*.js 

Question : how can this be done most correctly (maybe there is an additional package)?

As source code, an example of a simplified code from gulpfile for building css:

 var autoprefixer = require('autoprefixer'), gulp = require('gulp'), postcss = require('gulp-postcss'), rename = require('gulp-rename'); // PostCSS Plugins var plugins = [ autoprefixer() ]; // Paths var source = 'src'; var output = source; // Build Styles gulp.task('build:styles', function () { return gulp.src(source + '/**/*.css') .pipe(postcss(plugins)) .pipe(rename({ suffix: '.compile' })) .pipe(gulp.dest(output)); }); gulp.task('build', ['build:styles']); 

    1 answer 1

    In general, came up with this:

     var autoprefixer = require('autoprefixer'), gulp = require('gulp'), postcss = require('gulp-postcss'), rename = require('gulp-rename'); // PostCSS Plugins var plugins = [ autoprefixer() ]; // Paths var source = 'src'; var output = source; // Build Styles gulp.task('build:styles', function () { return gulp.src(source + '/**/*.css') .pipe(postcss(plugins)) .pipe(rename(function (path) { strPath = path.dirname; path.dirname = strPath.replace('assets/','assets-build/') })) .pipe(gulp.dest(output)); }); gulp.task('build', ['build:styles']); 

    Added a function that in each path replaces the first occurrence of assets with assets-build using the gulp-rename plugin.

    • Is there any point in assigning the global value path.dirname ? - Vladimir Gamalyan 2:44 pm
    • Without strPath, of course, it works too. Therefore, as you like, I am used to creating a new variable, if there is at least one manipulation. - alxshelepenok
    • I only about the fact that it is global, I thought, maybe it is somehow used somewhere else. - Vladimir Gamalyan