Gulp: Comment concatuer des composants de bower après le téléchargement de toutes les libs?

J'utilise "gulp-bower" pour installer automatiquement toutes les libs de bower.json, je veux aussi gulp pour réduire toutes les libs une fois qu'elles ont été téléchargées. C'est mon 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']);

Si je cours ceci j'ai eu cette erreur.

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 does not exist at /Users/yizhou/Documents/Yi/bower_components
    at Error (native)
    at module.exports (/Users/yizhou/Documents/Yi/node_modules/main-bower-files/lib/index.js:76:71)
    at Gulp. (/Users/yizhou/Documents/Yi/gulpfile.js:16:21)
    at module.exports (/Users/yizhou/Documents/Yi/node_modules/gulp/node_modules/orchestrator/lib/runTask.js:34:7)
    at Gulp.Orchestrator._runTask (/Users/yizhou/Documents/Yi/node_modules/gulp/node_modules/orchestrator/index.js:273:3)
    at Gulp.Orchestrator._runStep (/Users/yizhou/Documents/Yi/node_modules/gulp/node_modules/orchestrator/index.js:214:10)
    at Gulp.Orchestrator.start (/Users/yizhou/Documents/Yi/node_modules/gulp/node_modules/orchestrator/index.js:134:8)
    at /usr/local/lib/node_modules/gulp/bin/gulp.js:129:20
    at process._tickCallback (node.js:355:11)
    at 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
0

1 Réponses

gulp runs every task asynchronously by default, to improve performance. If you want to run in sequence, you need to explicit declare dependencies:

gulp.task('minifyBower', ['bower'], function() { /* ... */ });

Maintenant, minifyBower ne s'exécutera que lorsque bower sera exécuté. Si vous avez besoin de choses plus complexes, vous devriez utiliser quelque chose comme run-sequence .

0
ajouté