Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 !

like image 296
alienlebarge Avatar asked Oct 10 '13 13:10

alienlebarge


People also ask

What is grunt concat?

Concatenating with a custom separator In this example, running grunt concat:dist (or grunt concat because concat is a multi task) will concatenate the three specified source files (in order), joining files with ; and writing the output to dist/built. js . // Project configuration.

What is Gruntfile JS used for?

Grunt is a JavaScript task runner, a tool used to automatically perform frequent tasks such as minification, compilation, unit testing, and linting. It uses a command-line interface to run custom tasks defined in a file (known as a Gruntfile).

How do you check if a task exist in grunt?

Check with the name, if a task exists in the registered tasks.

What is grunt source?

In short, Grunt is an open source JavaScript project that automates repetitive tasks you often have to do as a web developer. With Grunt, you can automate tasks like minification, unit testing, and preparing your files and website assets for production use.


2 Answers

Here's what I've used:

copy: {
  main: {
    expand: true,
    cwd: 'folder1/folder2/pckg/',
    src: ['**'],
    dest: 'dist/'
  }
}
like image 85
alienlebarge Avatar answered Nov 03 '22 06:11

alienlebarge


use flatten:true

copy: {
    main: {
        files: [ 
            {expand: true, src: ['components/xxx/*'], dest: 'dist/', flatten: true}
        ]
    }
}
like image 16
pdem Avatar answered Nov 03 '22 08:11

pdem