简体   繁体   English

如何使用Gulp安装Bower

[英]How to use gulp install bower

I want to do something like this when I run gulp: 我想在执行gulp时执行以下操作:

1.use "gulp-bower" to install all dependency from bower.json. 1.使用“ gulp-bower”从bower.json安装所有依赖项。

2.Use "main-bower-files" to find all bower component and concat them into one file 2.使用“ main-bower-files”查找所有凉亭组件并将它们连接到一个文件中

var gulp = require('gulp');
var bower = require('gulp-bower');
var mainBowerFiles = require('main-bower-files');

gulp.task('default', function () {
    return bower()
        .pipe(gulp.src(mainBowerFiles()))
        .pipe(concat('lib.js'))
        .pipe(gulp.dest('static/lib'));
});

but this will give Error: Bower components directory does not exist first, then download the bower components after. 但这会导致错误:首先不存在Bower组件目录,然后再下载Bower组件。 How can you download the components first then run main-bower-files 如何先下载组件,然后运行主文件

gulp-bower runs asynchronously, so it moves along to the next part of the pipe before the files have finished downloading. gulp-bower异步运行,因此在文件下载完成之前,它会移至管道的下一部分。 To solve this, you'll need to separate your tasks: 为了解决这个问题,您需要将您的任务分开:

var gulp = require('gulp');
var bower = require('gulp-bower');
var concat = require('gulp-concat');
var mainBowerFiles = require('main-bower-files');

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

gulp.task('bower-concat', ['bower'], function () {
    return gulp.src(mainBowerFiles())
        .pipe(concat('lib.js'))
        .pipe(gulp.dest('static/lib'));
});

gulp.task('default', ['bower-concat']);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM