How to copy bower dependencies in wwwroot with wiredep (mvc 6)

620 Views Asked by At

I tried to create a task who allow to download and inject dependencies in my index with gulp and wiredep. It works but like my folder bower_components it isn't in my wwwroot my scripts's links are wrong. Errors are 'Uncaught SyntaxError: Unexpected token <' for all my links. So, I tried to change my destination folder but when I run my task, I catch a new error 'bootstrap isn't installed'. And I can't reinstall bootstrap twice times in the same project.

This is my gulp task:

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 + "/"))
});

my project architecture: my project architecture:

and my index.html (head):

  <!--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-->

So I already tested this for my gulp task :

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 + "/"))
    });

With this code, the error is the bower not installed.

Thank you for all the help you could give me.

1

There are 1 best solutions below

1
On

If you have a .bowerrc file with:

{
    "directory": "wwwroot/lib"
}

then on the bower install, it will be copied to the destination folder.