How can I integrate Bower with Gulp.js? -
i trying write gulp task few things
- install bower dependencies
- concat dependencies 1 file in order of dependencies
i hoping without having specify paths dependencies. know there command bower list --paths
unsure of if possible tie together.
any thoughts?
edit
so trying use gulp-bower-files , getting eaccess error , not generating concatenated file.
gulpfile.js
var gulp = require('gulp'); var bower = require('bower'); var concat = require('gulp-concat'); var bower_files = require('gulp-bower-files'); gulp.task("libs", function(){ bower_files() .pipe(concat('./libs.js')) .pipe(gulp.dest("/")); });
bower.json
{ "name": "ember-boilerplate", "version": "0.0.0", "dependencies": { "ember": "1.6.0-beta.1", "ember-data": "1.0.0-beta.7" } }
and keep coming across error
events.js:72 throw er; // unhandled 'error' event ^ error: eacces, open '/libs.js'
use main-bower-files
it grabs production (main) files of bower packages defined in project's bower.json , use them gulp src task.
integrate in gulpfile:
var mainbowerfiles = require('main-bower-files');
i made task grabs production files, filters css/js/fonts , outputs them in public folder in respective subfolders (css/js/fonts).
here's example:
var gulp = require('gulp'); // define plug-ins var flatten = require('gulp-flatten'); var gulpfilter = require('gulp-filter'); // 4.0.0+ var uglify = require('gulp-uglify'); var minifycss = require('gulp-minify-css'); var rename = require('gulp-rename'); var mainbowerfiles = require('main-bower-files'); // define paths variables var dest_path = 'www'; // grab libraries files bower_components, minify , push in /public gulp.task('publish-components', function() { var jsfilter = gulpfilter('**/*.js'); var cssfilter = gulpfilter('**/*.css'); var fontfilter = gulpfilter(['**/*.eot', '**/*.woff', '**/*.svg', '**/*.ttf']); return gulp.src(mainbowerfiles()) // grab vendor js files bower_components, minify , push in /public .pipe(jsfilter) .pipe(gulp.dest(dest_path + '/js/')) .pipe(uglify()) .pipe(rename({ suffix: ".min" })) .pipe(gulp.dest(dest_path + '/js/')) .pipe(jsfilter.restore()) // grab vendor css files bower_components, minify , push in /public .pipe(cssfilter) .pipe(gulp.dest(dest_path + '/css')) .pipe(minifycss()) .pipe(rename({ suffix: ".min" })) .pipe(gulp.dest(dest_path + '/css')) .pipe(cssfilter.restore()) // grab vendor font files bower_components , push in /public .pipe(fontfilter) .pipe(flatten()) .pipe(gulp.dest(dest_path + '/fonts')); });
Comments
Post a Comment