grunt-contrib-copy - 复制时忽略文件夹 [英] grunt-contrib-copy - ignore folder when copying

查看:229
本文介绍了grunt-contrib-copy - 复制时忽略文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给出以下源代码树:

Given the following source tree:

dev
 丨- psd
     丨- psd.psd
     丨- png.png
 丨- css
     丨- css.css
 丨- image
     丨- 1.jpg
     丨- 2.png
 丨html.html

如何将pub目录复制到忽略psd文件夹为见下面?

How do I copy to the pub directory ignoring the psd folder as seen below?

pub
 丨- css
     丨- css.css
 丨- image
     丨- 1.jpg
     丨- 2.png
 丨html.html

我试过以下内容:

I tried the following:

{
 expand: true,
 src: ['dev/**/*', '!dev/psd/**/*'],
 dest: 'pub/'
}

但是,这会导致一个空的 psd 目录

But this results in an empty psd directory

推荐答案

请尝试遵循Gruntfile.js。它忽略了psd目录。解决方案可在以下问题中找到。

Try following Gruntfile.js. It ignores psd directory. Solution found in following question.

module.exports = function(grunt) {

  // Project configuration.
  grunt.initConfig({
        copy: {
          main: {
            src: ['**/*',  '!**/psd/**'],
            expand: true,
            cwd: 'dev',
            dest: 'pub',
          }
    }
  });

  // Load the plugin that provides the "copy" task.
    grunt.loadNpmTasks('grunt-contrib-copy');

  // Default task(s).
  grunt.registerTask('default', ['copy']);

};

示例设置

example setup.

mkdir gruntQuestion1
cd gruntQuestion1/
mkdir dev
mkdir dev/psd
mkdir dev/css
mkdir dev/image
touch dev/html.html
touch dev/psd/psd.psd
touch dev/psd/png.png
touch dev/css/css.css
touch dev/image/1.jpg
touch dev/image/2.png


atilla$ rm -rf pub/
atilla$ grunt
Running "copy:main" (copy) task
Created 2 directories, copied 4 files

Done, without errors.
atilla$ tree pub/
pub/
├── css
│   └── css.css
├── html.html
└── image
    ├── 1.jpg
    └── 2.png

2 directories, 4 files    

这篇关于grunt-contrib-copy - 复制时忽略文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆