2014-02-24 51 views
0

我正在使用Bower和GruntJS。我認爲grunt-bowercopy會在完成後刪除bower_components文件夾,但這種情況沒有發生。Can GruntJS可以在複製文件後移除bower_components文件夾嗎?

grunt-bowercopy可以在將文件複製到我想要的位置後刪除bower_components文件夾嗎?

這裏是我的文件夾設置:

->Project 
    ->Themes 
     ->Theme 
      ->assets 
       ->scripts 
       ->styles 
    ->tools 
     ->build 
      ->bower_components 
      ->bower.json 
      ->gruntfile.js 
      ->package.json 

這裏是我如何運行咕嚕-bowercopy在我gruntfile.js

module.exports = function (grunt) { 

// Loads the necessary tasks for this Grunt file. 
    require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks); 

    // Project configuration. 
    grunt.initConfig({ 

     pkg: grunt.file.readJSON('package.json'), 

     bowercopy: { 
      options: { 
      clear: true 
      }, 
      js: { 
      options: { 
       destPrefix: '../../Themes/Theme/assets/' 
      }, 
      //The key is the destination file. The value is the file from the bower_components folder 
      //The files will be added to a scripts folder at the location: ../../themes/3MTheme/assets/scripts 
      //The key is the name of the folder that is copied into the /assets folder. 
      src : 'scripts' 

      }, 
      css: { 
      options: { 
       destPrefix: '../../Themes/Theme/assets/' 
      }, 
      src: 'styles' 

      } 
     } 

     // Custom task, executed via the command "grunt bowercopy" 
     grunt.registerTask('bower', ['bowercopy']); 
};  
+0

如果在構建項目後刪除bower_components文件夾,則需要再次爲下一個版本安裝這些組件,對吧?你爲什麼要刪除該文件夾?它僅用於開發目的,不會進入dist文件夾。 –

+0

@Sergey,我正在從共享服務器複製一些文件。這些文件可能會偶爾被其他人更新,我想確保我將這些最新的更新拉下來。 – Mdd

回答

-1

我發現asnswer。我在選擇使用clear: true當它應該是clean: true

這工作我gruntfile.js

module.exports = function (grunt) { 

// Loads the necessary tasks for this Grunt file. 
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks); 

// Project configuration. 
grunt.initConfig({ 

    pkg: grunt.file.readJSON('package.json'), 

    bowercopy: { 
     options: { 
     clean: true 
     }, 
     js: { 
     options: { 
      destPrefix: '../../Themes/Theme/assets/' 
     }, 
     //The key is the destination file. The value is the file from the bower_components folder 
     //The files will be added to a scripts folder at the location: ../../themes/3MTheme/assets/scripts 
     //The key is the name of the folder that is copied into the /assets folder. 
     src : 'scripts' 

     }, 
     css: { 
     options: { 
      destPrefix: '../../Themes/Theme/assets/' 
     }, 
     src: 'styles' 

     } 
    } 

    // Custom task, executed via the command "grunt bowercopy" 
    grunt.registerTask('bower', ['bowercopy']); 
};  
0

它似乎並不彷彿咕嚕-bowercopy做到這一點你,但我已經做了運行測試命令之前用於清除報告的類似內容。

只需創建一個名爲cleanbowercopy的自定義任務,即在您正在清理的目錄上執行rmdir

然後更新您的註冊任務bowercopy後調用它:

grunt.registerTask('bower',['bowercopy','cleanbowercopy']); 

這樣,它會完成你在同一命令中尋求什麼,如果你寧願清理目錄的,甚至可以重複使用一個不同的時間點。

+0

謝謝!這是一個非常好的主意。它看起來像grunt-bowercopy將刪除bower_components文件夾,我只是沒有發現我的錯誤,直到我在這裏發佈後。 – Mdd

+0

啊,甚至更好。無論如何感謝upvote! –

相關問題