Bower 的 Wiredep 不注入文件

wiredep for bower not injecting files

我的目录结构如下:

bower_components
node_modules
src
index.html
bower.json
package.json
gulpfile.js
.gitignore

我有一个 gulp 任务来注入 Bower 依赖项,如下所示:

gulp.task('bower-inject', function () {
    gulp.src('./index.html')
        .pipe(wiredep())
        .pipe(gulp.dest('./'));
});

index.html

    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <link rel="shortcut icon" href="src/assets/images/favicon.ico">
        <title>ABC</title>

        <!-- bower:css -->
        <!-- endbower -->

        <!-- inject:css -->
        <!-- this is done with gulp inject which works as expected -->
        <!-- endinject -->
    </head>
    <body ng-controller="AppController as appVm">

        <div ui-view></div>

        <!-- bower:js -->
        <!-- endbower -->

        <!-- inject:js -->
        <!-- done via gulp-inject and works as expected -->
        <!-- endinject -->
    </body>

bower.json

"devDependencies": {
    "angular": "1.4.0",
    "angular-bootstrap": "~0.13.0",
    "angular-ui-router": "~0.2.15",
    "bootstrap": "~3.3.4",
    "modernizr": "~2.8.3",
    "font-awesome": "~4.3.0"
  }

这是我在 运行 任务时看到的 :

[00:24:50] Starting 'bower-inject'... [00:24:50] Finished 'bower-inject' after 14 ms

知道我在这里遗漏了什么吗?

这就是最终对我有用的方法:

gulp.task('inject', function () {
    var target = gulp.src('./index.html');

    var sources = gulp.src(['src/**/*.js', 'src/**/*.css'], {read: false});

    return target
        .pipe(wiredep({
            devDependencies: true
        }))
        .pipe(inject(sources))
        .pipe(gulp.dest('./'));
});

当您将包安装为依赖项而非开发依赖项时,Wiredep 将注入脚本标签。 所以运行 bower install --save angular angular-bootstrap angular-ui-router bootstrap modernizr font-awesome 然后 运行 你的 gulp build 应该可以做到。

注意:一些软件包需要覆盖 bower.json 上的配置。 Check here 在需要时获取有关 Bower 覆盖的信息。