Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a clean front-end workflow with bower and gulp?

I have been really struggling to figure out how to cleanly install and update client-side assets from 3rd-party vendors. All that I really want to do is to fetch the current versions and copy the production-ready files into a fixed location. The best I have been able to come up with so far is this ugly thing:

gulp.task('bower', ['clean','load'], function(){
    var bowerFilesToMove = [
        'angular*/*',
        'bootstrap/dist/*',
        'fontawesome/*',
        'jasny-bootstrap/dist/*',
        'jcrop/css/*',
        'jcrop/js/*',
        'jquery/dist/*',
        'jquery-align-column/*',
        'jquery-autosize/*',
        'jqueryui/ui/minified/*',
        'moment/min/*',
        'select2/*',
        'underscore/*',
    ];

    bowerFilesToMove.forEach(function(filespec){
        gulp.src('./bower_components/'+filespec+'.css')
            .pipe(flatten())
            .pipe(gulp.dest('public/vendor/css'));
    });

    bowerFilesToMove.forEach(function(filespec){
        gulp.src('./bower_components/'+filespec+'.js')
            .pipe(flatten())
            .pipe(gulp.dest('public/vendor/js'));
    });

    bowerFilesToMove.forEach(function(filespec){
        gulp.src('./bower_components/'+filespec+'.map')
            .pipe(flatten())
            .pipe(gulp.dest('public/vendor/js'));
    });

    gulp.src('./bower_components/jqueryui/themes/*')
        .pipe(gulp.dest('public/vendor/css/themes'));

    gulp.src('./bower_components/bootstrap/dist/fonts/*')
        .pipe(gulp.dest('public/vendor/fonts'));

    gulp.src('./bower_components/fontawesome/fonts/*')
        .pipe(gulp.dest('public/vendor/fonts'));
});

gulp.task('clean', function(){
    return gulp.src('./public/vendor')
        .pipe(clean({force: true}));
});

gulp.task('load', function(){
    return bower();
});

I've been reading a lot to try to figure out the best practices and tools for client deployments, but have just been getting myself more and more confused. I'm sure that the front-end will be more complex than just selecting packages and running "composer update", but this seems pretty kludgy. What are some better ways to handle it?

like image 978
joel Avatar asked Apr 27 '14 04:04

joel


1 Answers

Whenever I'm working on a production-level app, rather than manually handling the copying of specific vendor assets into a directory, I allow my build-process to take a look at my relevant markup files referencing any <script> tags and ascertain what needs to be copied over. This avoids copying or deploying scripts that aren't actually in use.

If you would like to take a look at how we on the Yeoman team use this type of setup, take a look at our Gulp file here, which also uses the useref task:

https://github.com/yeoman/generator-gulp-webapp/blob/master/app/templates/gulpfile.js#L27

like image 82
addyo Avatar answered Oct 08 '22 21:10

addyo