Wiredep Gulp依赖注入不起作用

时间:2017-08-27 23:59:39

标签: dependency-injection gulp bower wiredep

这是我的gulp任务

gulp.task('inject', function() {
  var wiredep = require('wiredep').stream;
  var options = {
    bowerJson: require('./bower.json'),
    directory: './public/lib'
  };
  return gulp.src('./src/views/*.html')
  .pipe(wiredep(options))
  .pipe(gulp.dest('./src/views'));
});

这些是我的bower.json

中的依赖项
  "dependencies": {
    "bootstrap": "^3.3.7",
    "font-awesome": "^4.7.0"
  }

当我在命令行中运行'gulp inject'时,它似乎可以正常工作,但我的依赖项不会出现在index.html中。

1 个答案:

答案 0 :(得分:0)

我尝试使用您发布的完全相同的gulp任务进行重现,并正确注入所有文件。

我没有看到你的index.html,但是检查你的任务,唯一不同的是bower目录。您确定 bower.json 文件中还设置了 ./ public / lib 吗?

另外,你在html上添加这些标签吗?

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

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

这是我的index.html的样子:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <!-- bower:css -->
    <!-- endbower -->
    <title>Wiredep test</title>
</head>
<body>

<!-- bower:js -->
<!-- endbower -->
</body>
</html>