2015-05-31 147 views
0

Visual Studio 2015 ASP.NET 5模板從gulpfile.js和幾個已安裝的bower組件開始。我已經添加了額外的bower組件(angularjs),它們被複制到我的wwwroot \ lib文件夾中。我已將自己的庫中的一個添加到我稱爲ext_modules \ dist的文件夾中。我正在向gulpfile.js添加一個任務,以將我的文件(包含單個.js和.css文件)複製到wwwroot \ lib文件夾中。我正在遵循gulpfile.js中已有的示例語法。但是,從我的ext_modules文件夾複製任何內容。請參閱下面的JS,輸出和文件夾結構。在VS 2015中使用gulp複製不復制文件

/// <binding Clean='clean' /> 

var gulp = require("gulp"), 
    rimraf = require("rimraf"), 
    fs = require("fs"); 

eval("var project = " + fs.readFileSync("./project.json")); 

var paths = { 
    bower: "./bower_components/", 
    extmodules: "./ext_modules/", 
    lib: "./" + project.webroot + "/lib/" 
}; 

gulp.task("clean", function (cb) { 
    rimraf(paths.lib, cb); 
}); 

gulp.task("copy", ["clean"], function() { 
    var bower = { 
     "angular": "angular.js/*.js", 
     "bootstrap": "bootstrap/dist/**/*.{js,map,css,ttf,svg,woff,eot}", 
     "bootstrap-touch-carousel": "bootstrap-touch-carousel/dist/**/*.{js,css}", 
     "hammer.js": "hammer.js/hammer*.{js,map}", 
     "jquery": "jquery/jquery*.{js,map}", 
     "jquery-validation": "jquery-validation/jquery.validate.js", 
     "jquery-validation-unobtrusive": "jquery-validation-unobtrusive/jquery.validate.unobtrusive.js", 
    }; 

    var extmodules = { 
     "ext-modules": "dist/*.{js,map,css,ttf,svg,woff,eot}" 
    }; 

    for (var module in bower) { /* This copy works fine*/ 
     console.log("Source: " + paths.bower + bower[module]); 
     console.log("Destination: " + paths.lib + module); 
     gulp.src(paths.bower + bower[module]) 
      .pipe(gulp.dest(paths.lib + module)); 
    }; 

    for (var module in extmodules) { /* This does not copy any files */ 
     console.log("Source: " + paths.extmodules + extmodules[module]); 
     console.log("Destination: " + paths.lib + module); 
     gulp.src(paths.extmodules + extmodules[module]) 
     .pipe(gulp.dest(paths.lib + module)); 
    }; 
}); 

這裏是我的控制檯日誌:

[11:17:57] Starting 'clean'... 
[11:17:57] Finished 'clean' after 11 ms 
[11:17:57] Starting 'copy'... 
Source: ./bower_components/angular.js/*.js 
Destination: ./wwwroot/lib/angular 
Source: ./bower_components/bootstrap/dist/**/*.{js,map,css,ttf,svg,woff,eot} 
Destination: ./wwwroot/lib/bootstrap 
Source: ./bower_components/bootstrap-touch-carousel/dist/**/*.{js,css} 
Destination: ./wwwroot/lib/bootstrap-touch-carousel 
Source: ./bower_components/hammer.js/hammer*.{js,map} 
Destination: ./wwwroot/lib/hammer.js 
Source: ./bower_components/jquery/jquery*.{js,map} 
Destination: ./wwwroot/lib/jquery 
Source: ./bower_components/jquery-validation/jquery.validate.js 
Destination: ./wwwroot/lib/jquery-validation 
Source: ./bower_components/jquery-validation-unobtrusive/jquery.validate.unobtrusive.js 
Destination: ./wwwroot/lib/jquery-validation-unobtrusive 
Source: ./ext_modules/dist/*.{js,map,css,ttf,svg,woff,eot} 
Destination: ./wwwroot/lib/ext-modules 
[11:17:57] Finished 'copy' after 21 ms 
Process terminated with code 0. 

VSSolutionExplorer

+0

由於'。/ ext_modules/dist'在屏幕截圖中沒有展開,我不知道它裏面有什麼文件......你是否打算把所有文件都包含在'。/ ext_modules/dist'的子文件夾中? (''ext-modules「:」dist/**/*。{js,map,css,ttf,svg,woff,eot}「') –

+0

dist僅包含2個文件。一個js和css文件。沒有文件夾。我也嘗試過**語法。 –

+0

哎。我的下一個建議是從命令行運行它,但是現在它正在工作......你是否通過手錶觸發了它?我知道可以緩存... –

回答

1

我能得到這個工作,如果在gulpfile.js我明確鼠標右鍵,選擇「任務運行資源管理器」,則窗口顯示停靠在底部。在任務中將會列出任務。然後,您可以右鍵單擊要運行的任務,然後選擇「運行」。