如何使用wiredep获取正确的依赖注入路径?

时间:2016-03-24 08:17:29

标签: javascript wiredep

我正在尝试使用wiredep在我的应用中包含来自bower的css和js文件。我在index.html中有原始app/rawHtml/index.html(html删除bower css和js),如下面的文件夹树所示:

 app
   ├── bower_components
   │   ├── lib1
   │   │   ├── lib1.css
   │   │   ├── lib1.js
   │   │   ├── bower.json
   │   │   ├── package.json
   │   │   └── README.md
   │   ├── lib2
   │   │   ├── lib2.css
   │   │   ├── lib2.js
   │   │   ├── bower.json
   │   │   ├── package.json
   │   │   └── README.md
   │   │       ├── globals.js
   │   │       ├── locale-header.js
   │   │       └── test-header.js
   ├── index.html
   └── rawHtml
       └── index.html

我想使用app/rawHtml/index.htmlapp/index.htmlwiredep的gulpfile如下:

gulpfile.js

gulp.task('bower:dev', function () {
   return gulp.src('app/rawHtml/index.html')
   .pipe(wiredep())
   .pipe(gulp.dest('app/'));
});

现在创建了index.html文件。但是相对于app/rawHtml/index.html

,依赖关系如下所示
 <!-- bower:css --> 
 <link rel="stylesheet" href="../bower_components/lib1/lib1.css" />                                                             
 <link rel="stylesheet" href="../bower_components/lib2/lib2.css" />

<!-- bower:js -->
<script src="../bower_components/lib1/lib1.js"></script>
<script src="../bower_components/lib2/lib2.js"></script>

而不是关于目标文件app/index.html,如下所示:

 <!-- bower:css --> 
 <link rel="stylesheet" href="bower_components/lib1/lib1.css" />                                                             
 <link rel="stylesheet" href="bower_components/lib2/lib2.css" />

<!-- bower:js -->
<script src="bower_components/lib1/lib1.js"></script>
<script src="bower_components/lib2/lib2.js"></script>

我尝试将源和目标index.html保留在同一目录中,但我没有找到重命名目标文件的选项。我如何使用wiredep以便获得正确的注射路径?

1 个答案:

答案 0 :(得分:0)

好的,我遇到了同样的问题。我想你需要在运行index.html命令之前将app放在wiredep目录中。

gulpfile.js

gulp.task('bower:dev', function () {
    return gulp.src('app/rawHtml/index.html')
    .pipe(gulp.dest('app/'))
    .pipe(wiredep())
    .pipe(gulp.dest('app/'));
});