Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
394 views
in Technique[技术] by (71.8m points)

gruntjs - grunt-contrib-copy - ignore folder when copying

Given the following source tree:

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

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/'
}

But this results in an empty psd directory

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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    

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...