Last active
August 29, 2015 14:21
-
-
Save vincent-zurczak/0ec946faa3dd409c6cfb to your computer and use it in GitHub Desktop.
Copy Bower dependencies with Gulp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Include our plug-ins | |
var gulp = require('gulp'); | |
var bowerMain = require('bower-main'); | |
var mainBowerFiles = require('main-bower-files'); | |
var exists = require('path-exists').sync; | |
var gulpIgnore = require('gulp-ignore'); | |
// Create some task | |
gulp.task( 'copy-bower-dep', function() { | |
// Copy minified resources (Bower) | |
gulp.src( bowerMain( 'js', 'min.js' ).minified, {base: './my-bower-components/dir'}) | |
.pipe( gulp.dest( './target/dist/lib' )); | |
gulp.src( bowerMain( 'css', 'min.css' ).minified, {base: './my-bower-components/dir'}) | |
.pipe( gulp.dest( './target/dist/lib' )); | |
// Copy non-minified resources (Bower) | |
// Notice we filter these resources to distinguish which one are minified. | |
gulp.src( mainBowerFiles(), {base: './my-bower-components/dir'}) | |
.pipe( gulpIgnore.include( keepNonMinified )) | |
.pipe( gulp.dest( './target/dist/lib' )); | |
}); | |
/* | |
* A function that checks whether a Bower file has a minified version. | |
*/ | |
function keepNonMinified( file ) { | |
var keep = true; | |
if( file.path.match( '\.js$' )) { | |
var minPath = file.path.replace( '.js', '.min.js' ); | |
keep = ! exists( minPath ); | |
} else if( file.path.match( '\.css$' )) { | |
var minPath = file.path.replace( '.css', '.min.css' ); | |
keep = ! exists( minPath ); | |
} | |
// gutil.log( file.path + ' => ' + keep ); | |
return keep; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For the record, I posted a more simple solution here.