主要的bower文件gulp返回空数组

3
我正在尝试使用插件main-bower-files,但似乎无法从bower_components中提取目录。它的调试信息显示它有正确的文件,但它没有返回一个数组。
#here you can see the debug finding the places
PackageCollection add        angular bower_components/angular
PackageCollection add        json3 bower_components/json3
PackageCollection add        es5-shim bower_components/es5-shim
PackageCollection add        jquery bower_components/jquery
PackageCollection add        angular-resource bower_components/angular-resource
PackageCollection add        angular-cookies bower_components/angular-cookies
PackageCollection add        angular-sanitize bower_components/angular-sanitize
PackageCollection add        angular-animate bower_components/angular-animate
PackageCollection add        angular-touch bower_components/angular-touch
PackageCollection add        angular-ui-router bower_components/angular-ui-router

[22:25:31] [] #< this is the result of calling require('main-bower-files')()

这是我的Gulp任务,用于注入(插入)内容:

var bowerFiles = require('main-bower-files')


gulp.task('inject', function() {
  util.log(bowerFiles({debugging:true}))
  gulp.src('app/index.jade')
    .pipe(jade({pretty: true}))
    .pipe(inject(gulp.src(bowerFiles()), {starttag: '<!-- inject:{{ext}}-->', endtag: '<!-- endinject-->'}))
    .pipe(inject(gulp.src('.tmp/**/*.js', {read: false}), {starttag: '<!-- inject:files:{{ext}}-->', endtag: '<!-- endinject-->'}))
    .pipe(connect.reload())
    .pipe(gulp.dest('.tmp'))
})

我遇到了完全相同的问题,使用的是macOS和gulp 3.8.6。 - Nicolas Zozol
2个回答

3

如果你在 bower.json 中将依赖项作为 devDependencies,你需要添加 ' includeDev:true

查看

includeDev 类型:mixed 默认值:false

有两种方式可以包含 devDependencies:

将此选项设置为 inclusive 或 true,将 devDependencies 添加到你的 dependencies 中,或使用 exclusive 将它们排除在外。


如果你想要添加自己的文件,也可以包括自身(includeSelf),默认情况下为false。请查看https://www.npmjs.com/package/main-bower-files。 - chrilith

1

您需要安装Bower并运行Bower install

所以:

  • 安装Node和npm,我想这已经完成了
  • 运行npm install使您的项目准备好npm,并安装package.json中的内容
  • 安装bower:sudo npm install -g bower
  • 运行bower install将您的bower.json依赖项复制到./bower_components目录中
  • 安装gulp:npm install -g gulp
  • 构建您的项目:gulp build
  • 检查它:gulp serve,然后您就可以使用它了

嗯,几乎是自动构建...


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接