27

我想用 grunt.js复制/pckgto的内容。/dist这是结构:

  |-- folder1
  |     |
  |     |-- folder2
  |           |
  |           |-- pckg
  |                 |
  |                 |--myfolder
  |                 |    |
  |                 |    |-- myfiles
  |                 |
  |                 |--myfiles
  |
  |
  |-- dist
        |
        |--myfolder
        |   |
        |   |-- myfiles
        |
        |--myfiles

这是我的Gruntfile.js

module.exports = function (grunt) {

  // Package configuration
  grunt.initConfig({

    // Metadata
    pkg: grunt.file.readJSON('package.json'),

    //Copy files
    copy: {
      main: {
        expand: true,
        src: 'folder1/folder2/pckg/**',
        dest: 'dest/'
      }
    }

  });

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

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

当我运行 Grunt 时,它会保持路径。它将所有内容复制到dit/folder1/folder2/pckg. 怎么了 ?

谢谢你的帮助 !

4

2 回答 2

54

这是我用过的:

copy: {
  main: {
    expand: true,
    cwd: 'folder1/folder2/pckg/',
    src: ['**'],
    dest: 'dist/'
  }
}
于 2013-10-11T05:39:01.727 回答
16

使用扁平化:真

copy: {
    main: {
        files: [ 
            {expand: true, src: ['components/xxx/*'], dest: 'dist/', flatten: true}
        ]
    }
}
于 2013-10-10T13:49:06.377 回答