如何使用grunt.js复制没有完整路径的文件? [英] How to copy files without the full path with grunt.js?

查看:122
本文介绍了如何使用grunt.js复制没有完整路径的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用grunt.js将 / pckg 的内容复制到 / dist
这里是结构:

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

这是我的 Gruntfile.js < code

$ $ p $ module.exports =函数(grunt){

//程序包配置
grunt.initConfig({

//元数据
pkg:grunt.file.readJSON('package.json'),

//复制文件
副本:{
main:{
展开:true,
src:'folder1 / folder2 / pckg / **',
dest:'dest /'
}
}

});

//载入提供复制任务的插件。
grunt.loadNpmTasks('grunt-contrib-copy');

//默认任务。
grunt.registerTask('default',['copy']);
};

当我运行Grunt时,它保留了路径。它将所有内容复制到 dit / folder1 / folder2 / pckg 中。
有什么不对?



感谢您的帮助!

解决方案



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


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 !

解决方案

Here's what I've used:

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

这篇关于如何使用grunt.js复制没有完整路径的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆