1

我对 grunt 很陌生,所以我需要一些帮助。

我在官方上问过这个问题,gruntjs/grunt-contrib-copy但没有得到回应。

我想使用grunt-contrib-copy从某个目录复制文件到另一个目录,它们看起来像这样:

parentpath/ (source file)
    /assets/sass/bootstrap/
    /assets/sass/fontawesome/
    /assets/sass/storms/
    /assets/sass/wordpress/
    /assets/sass/_layout.scss
    /assets/sass/_woocommerce.scss

childpath/ (destiny file)
    /assets/sass/bootstrap/
    /assets/sass/fontawesome/
    /assets/sass/storms/
    /assets/sass/wordpress/
    /assets/sass/_layout.scss
    /assets/sass/_woocommerce.scss

我的 gruntfile 是这样配置的:

copy: {
    parenttheme_bootstrap: {
        src: '<%= dirs.parentpath %>/assets/sass/bootstrap',
        dest: '<%= dirs.sass %>'
    },
    parenttheme_fontawesome: {
        src: '<%= dirs.parentpath %>/assets/sass/fontawesome',
        dest: '<%= dirs.sass %>'
    },
    parenttheme_storms: {
        src: '<%= dirs.parentpath %>/assets/sass/storms',
        dest: '<%= dirs.sass %>'
    },
    parenttheme_wordpress: {
        src: '<%= dirs.parentpath %>/assets/sass/wordpress',
        dest: '<%= dirs.sass %>'
    },
    parenttheme_partials: {
        files: [{
                expand: true,
                cwd: '<%= dirs.parentpath %>/assets/sass/',
                src: '_layout.scss',
                dest: '<%= dirs.sass %>'
            },
            {
                expand: true,
                cwd: '<%= dirs.parentpath %>/assets/sass/',
                src: '_woocommerce.scss',
                dest: '<%= dirs.sass %>'
        }]
    }
}

// parent Task
grunt.registerTask( 'parent', [
    'copy:parenttheme_bootstrap',
    'copy:parenttheme_fontawesome',
    'copy:parenttheme_storms',
    'copy:parenttheme_wordpress',
    'copy:parenttheme_partials',
    'sass',
    'postcss'
] );

当我运行父任务时, /assets/sass/bootstrap 文件夹被正确复制到他的命运中。部分文件也是如此。

但是由于某种原因,所有其他文件夹都没有被复制,我没有收到任何错误!

运行 grunt parent --verbose 我得到了这个:

Running tasks: parent

Running "parent" task

Running "copy:parenttheme_bootstrap" (copy) task
Verifying property copy.parenttheme_bootstrap exists in config...OK
Files: ../../childpath/assets/sass/bootstrap -> ../assets/sass
Options: encoding="utf8", processContent=false, processContentExclude=[], timestamp=false, mode=false
Creating ../assets/sass
Created 1 directory

Running "copy:parenttheme_fontawesome" (copy) task
Verifying property copy.parenttheme_fontawesome exists in config...OK
Files: ../../childpath/assets/sass/fontawesome -> ../assets/sass
Options: encoding="utf8", processContent=false, processContentExclude=[], timestamp=false, mode=false
Creating ../assets/sass
Created 1 directory

Running "copy:parenttheme_storms" (copy) task
Verifying property copy.parenttheme_storms exists in config...OK
Files: ../../childpath/assets/sass/storms -> ../assets/sass
Options: encoding="utf8", processContent=false, processContentExclude=[], timestamp=false, mode=false
Creating ../assets/sass
Created 1 directory

Running "copy:parenttheme_wordpress" (copy) task
Verifying property copy.parenttheme_wordpress exists in config...OK
Files: ../../childpath/assets/sass/wordpress -> ../assets/sass
Options: encoding="utf8", processContent=false, processContentExclude=[], timestamp=false, mode=false
Creating ../assets/sass
Created 1 directory

Running "copy:parenttheme_partials" (copy) task
Verifying property copy.parenttheme_partials exists in config...OK
Files: ../../childpath/assets/sass/_layout.scss -> ../assets/sass/_layout.scss
Files: ../../childpath/assets/sass/_woocommerce.scss -> ../assets/sass/_woocommerce.scss
Options: encoding="utf8", processContent=false, processContentExclude=[], timestamp=false, mode=false
Copying ../../childpath/assets/sass/_layout.scss -> ../assets/sass/_layout.scss
Reading ../../childpath/assets/sass/_layout.scss...OK
Writing ../assets/sass/_layout.scss...OK
Copying ../../childpath/assets/sass/_woocommerce.scss -> ../assets/sass/_woocommerce.scss
Reading ../../childpath/assets/sass/_woocommerce.scss...OK
Writing ../assets/sass/_woocommerce.scss...OK
Copied 2 files

任何人都知道我在这里做错了什么?

谢谢!

4

2 回答 2

1

我认为您只需要稍微尝试一下您的目录和文件规范。有几件事要尝试:

  1. 将通配模式添加到您的源路径,而不仅仅是目录名称,例如.../bootstrap/**/*.scss.
  2. 在目标路径中添加一个尾部斜杠,这样它显然是一个目录,例如dest: '<%= dirs.sass %>/'. grunt 可能正在复制到单个文件输出,而不是目录树。

一个小例子:

copy: {
    parenttheme_bootstrap: {
        src: '<%= dirs.parentpath %>/assets/sass/bootstrap/**/*.scss',
        dest: '<%= dirs.sass %>/'
    },
    parenttheme_fontawesome: {
        src: '<%= dirs.parentpath %>/assets/sass/fontawesome/**/*.scss',
        dest: '<%= dirs.sass %>/'
    },
于 2015-08-25T15:48:01.287 回答
0

感谢@James 的建议,我通过更改为:

        sf2_bootstrap: {
            files: [{
                expand: true,
                cwd: '<%= dirs.sfpath %>/assets/sass/bootstrap/',
                src: '**/*.scss',
                dest: '<%= dirs.sass %>/bootstrap/'
            }]
        },

现在我的文件已正确复制。

詹姆斯解决方案,复制了我所有的文件,但是到了错误的目录,我不知道为什么。

于 2015-08-29T21:31:46.653 回答