我尝试创建一个允许使用gulp和wiredep在我的索引中下载和注入依赖项的任务。它工作,但像我的文件夹bower_components它不在我的wwwroot我的脚本的链接是错误的。错误是'Uncaught SyntaxError:Unexpected token<'我所有的链接。所以,我试图更改我的目标文件夹,但是当我运行我的任务时,我发现了一个新错误'未安装bootstrap'。而且我无法在同一个项目中重新安装两次bootstrap。
这是我的一项任务:
eval("var project = " + fs.readFileSync("./project.json"));
gulp.task('bower', function () {
gulp.src("./" + project.webroot + "/index.html")
.pipe(wiredep({
directory: "./bower_components/",
bowerJson: require('./bower.json')
}))
.pipe(gulp.dest("./" + project.webroot + "/"))
});
和我的index.html(头):
<!--bower:css-->
<link rel="stylesheet" href="../bower_components/bootstrap/dist/css/bootstrap.css" />
<link rel="stylesheet" href="../bower_components/bootstrap-touch-carousel/dist/css/bootstrap-touch-carousel.css" />
<!--endbower-->
<!--bower:js-->
<script src="../bower_components/jquery/dist/jquery.js"></script>
<script src="../bower_components/bootstrap/dist/js/bootstrap.js"></script>
<script src="../bower_components/jquery-ui/jquery-ui.js"></script>
<script src="../bower_components/jquery-validation/dist/jquery.validate.js"></script>
<script src="../bower_components/jquery-validation-unobtrusive/jquery.validate.unobtrusive.js"></script>
<script src="../bower_components/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js"></script>
<script src="../bower_components/hammer.js/hammer.js"></script>
<script src="../bower_components/bootstrap-touch-carousel/dist/js/bootstrap-touch-carousel.js"></script>
<script src="../bower_components/angular/angular.js"></script>
<script src="../bower_components/angular-route/angular-route.js"></script>
<script src="../bower_components/angular-resource/angular-resource.js"></script>
<script src="../bower_components/angular-ui-router/release/angular-ui-router.js"></script>
<script src="../bower_components/angular-animate/angular-animate.js"></script>
<script src="../bower_components/angular-cookies/angular-cookies.js"></script>
<script src="../bower_components/angular-parse/angular-parse.js"></script>
<script src="../bower_components/angular-locker/dist/angular-locker.min.js"></script>
<!--endbower-->
所以我已经为我的gulp任务测试了这个:
eval("var project = " + fs.readFileSync("./project.json"));
gulp.task('bower', function () {
gulp.src("./" + project.webroot + "/index.html")
.pipe(wiredep({
directory: "./"+project.webroot+"bower_components/",
bowerJson: require('./bower.json')
}))
.pipe(gulp.dest("./" + project.webroot + "/"))
});
使用此代码,错误是未安装的凉亭。
感谢您提供给我的所有帮助。
答案 0 :(得分:1)
如果您的.bowerrc文件包含:
{
"directory": "wwwroot/lib"
}
然后在bower安装上,它将被复制到目标文件夹。