复制文件后,GruntJS可以删除bower_components文件夹吗?

时间:2014-02-24 17:14:40

标签: javascript gruntjs bower

我正在使用Bower和GruntJS。我认为grunt-bowercopy会在完成后删除bower_components文件夹,但这不会发生。

将文件复制到我想要的位置后,grunt-bowercopy会删除bower_components文件夹吗?

这是我的文件夹设置:

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

以下是我在gruntfile.js中运行grunt-bowercopy的方法

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']);
};    

2 个答案:

答案 0 :(得分:0)

grunt-bowercopy似乎并没有为您做到这一点,但在运行测试命令之前,我已经为清除报告做了类似的事情。

只需创建自己的自定义任务,例如cleanbowercopy,它会对您要清理的目录执行rmdir

然后更新你的注册任务,在bowercopy之后调用它:

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

通过这种方式,它可以在同一个命令中完成您所寻求的目标,如果您在不同的时间点清理目录,甚至可以重复使用。

答案 1 :(得分:-1)

我找到了答案。我在选项中使用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']);
};