2014-02-24 32 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! –

相关问题