gruntjsgrunt-contrib-copy

How to copy files without the full path with grunt.js?


I want to copy the content of /pckg to /dist with grunt.js. Here is the structure:

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

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

When I run Grunt, it keep the path. It copy everything in dit/folder1/folder2/pckg. What is wrong ?

Thanks for your help !


Solution

  • Here's what I've used:

    copy: {
      main: {
        expand: true,
        cwd: 'folder1/folder2/pckg/',
        src: ['**'],
        dest: 'dist/'
      }
    }