Gulp: copy files to the new structure



  • There are files with a view to:

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

    However, component may have any name.

    We need to get everything together with Gulp, replace it. assetsassets-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
    

    QuestionHow can this be done most correctly?

    As a reference, an example of a simplified code of gulpfile for the collection of 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']);



  • Anyway, I 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 replaces the first entry in each route assetsassets-build with a gulp-rename flame.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2