Gulp: How to concat bower components after all libs been download? -
i'm using "gulp-bower" auto install libs bower.json, want gulp minify libs once it's been download. code:
var gulp = require('gulp'); var sass = require('gulp-sass'); var concat = require('gulp-concat'); var bower = require('gulp-bower'); var mainbowerfiles = require('main-bower-files'); gulp.task('bower', function() { return bower() .pipe(gulp.dest("./bower_components")) }); gulp.task('minifybower', function() { return gulp.src(mainbowerfiles()) .pipe(concat('lib.js')) .pipe(gulp.dest('dist')) }); gulp.task('default', ['bower','minifybower']);
if run got error.
starting 'bower'... [11:23:06] using cwd: /users/yizhou/documents/yi [11:23:06] using bower dir: ./bower_components [11:23:06] starting 'minifybower'... [11:23:06] 'minifybower' errored after 1.53 ms [11:23:06] error: bower components directory not exist @ /users/yizhou/documents/yi/bower_components @ error (native) @ module.exports (/users/yizhou/documents/yi/node_modules/main-bower-files/lib/index.js:76:71) @ gulp.<anonymous> (/users/yizhou/documents/yi/gulpfile.js:16:21) @ module.exports (/users/yizhou/documents/yi/node_modules/gulp/node_modules/orchestrator/lib/runtask.js:34:7) @ gulp.orchestrator._runtask (/users/yizhou/documents/yi/node_modules/gulp/node_modules/orchestrator/index.js:273:3) @ gulp.orchestrator._runstep (/users/yizhou/documents/yi/node_modules/gulp/node_modules/orchestrator/index.js:214:10) @ gulp.orchestrator.start (/users/yizhou/documents/yi/node_modules/gulp/node_modules/orchestrator/index.js:134:8) @ /usr/local/lib/node_modules/gulp/bin/gulp.js:129:20 @ process._tickcallback (node.js:355:11) @ function.module.runmain (module.js:503:11) [11:23:06] bower cached git://github.com/jquery/jquery.git#2.1.4 [11:23:06] bower validate 2.1.4 against git://github.com/jquery/jquery.git#~2.1.4 [11:23:07] bower install jquery#2.1.4 [11:23:08] finished 'bower' after 2 s
gulp
runs every task asynchronously default, improve performance. if want run in sequence, need explicit declare dependencies:
gulp.task('minifybower', ['bower'], function() { /* ... */ });
now minifybower
won't run until bower
run. if need more complex stuff, should use run-sequence.
Comments
Post a Comment