Volodymyr Machula
Volodymyr Machula

Reputation: 1604

Corrupted copy using grunt-contrib-copy

I have an issue when copy a lot of files (images, pdf, etc) from one directory to another one. In a destination folder all these files is corrupted. I tried to use both noProcess and processContentExclude options but it brought no results.

My copy task config looks like this:

copy: {
  assets_images: {
    options: {
      noProcess: ['**/*.{png,gif,jpg,ico,pdf}']
    },
    expand: true,
    cwd: 'static/images/',
    src: '**',
    dest: 'dist/assets/images/'
  },
  assets_data: {
    options: {
      noProcess: ['**/*.{png,gif,jpg,ico,pdf}']
    },
    expand: true,
    cwd: 'static/data/',
    src: '**',
    dest: 'dist/assets/data/'
  }
}

Could you please help me with this?

UPDATE:

I did some investigations and found out that binary code of the png files in the source and destionation folders are differ.

I suspect that copy task process files using wrong encoding (by default it is utf8). As I understand it process them as a binary files and utf8 is not a correct encoding in this case.

What would you recomend to do for fix this issue?

Upvotes: 4

Views: 839

Answers (1)

Guilherme Rodrigues
Guilherme Rodrigues

Reputation: 2854

In case you have a process function

The option name is processContentExclude, unless you're using version 0.5.0 or above, where it changed to noProcess according to https://github.com/gruntjs/grunt-contrib-copy#release-history

You can check your version with:

npm ls grunt-contrib-copy

Large copy config example from grunt-vtex:

copy:
      main:
        files: [
          expand: true
          cwd: 'src/'
          src: ['**'].concat(options.copyIgnore)
          dest: "build/<%= relativePath %>/"
        ]
      deploy:
        files: [
          expand: true
          cwd: "build/<%= relativePath %>/"
          src: ['**']
          dest: "#{pkg.deploy}/#{pkg.version}"
        ]
        options:
          processContentExclude: ['**/*.{png,gif,jpg,ico,psd,ttf,otf,woff,svg}']
          process: (src, srcpath) ->
            replaceFiles = grunt.config('deployReplaceFiles') ? grunt.config('deployReplaceFiles', glob.sync(options.replaceGlob))
            for file in replaceFiles when file.indexOf(srcpath) >= 0
              log "Replacing file...", file
              for k, v of options.replaceMap
                log "Replacing key", k, "with value", v
                src = src.replace(new RegExp(k, 'g'), v)
            return src

In case you don't have a process function

noProcess won't help if you don't have a process function.

If so, you should look at encoding option. https://github.com/gruntjs/grunt-contrib-copy#encoding

Maybe try encoding: null, as suggested here: https://github.com/gruntjs/grunt-contrib-copy/issues/64

Either way

Try and reproduce your problem in a minimal fashion - create a Gruntfile with only one task, copying only one image. This is not a common problem and maybe some other task is the culprit here.

Upvotes: 3

Related Questions