grunt复制移动项目外的构建文件夹

时间:2014-11-17 09:51:10

标签: javascript node.js gruntjs

您好,我的文件结构如下所示,

|-App
|------|src
|----------|js
|----------|img
|----------|css
|----------|less
|----------|tpl
|----------|index.php
|- Gruntfile.js (withing parent app folder)
|- package.json (withing parent app folder)

我要做的是将src文件夹的所有内容移动到构建文件夹中,构建文件夹在App文件夹之外创建,我不明白为什么,其次是什么时候复制src文件夹,它复制实际的src文件夹,我想复制它的所有子节点但没有父src文件夹,第三个副本忽略index.php文件为什么?下面是我目前的Gruntfile.js

    module.exports = function(grunt) {

  // Project configuration.
  grunt.initConfig({

      copy: {
        build: {
            cwd: '.',
            src: ['src/*/*'],
            dest: '../build',
            expand: true
        }
      },
      clean: {
        build: {
            cwd: '.',
            src: ['build']
        }
      }

  });

  grunt.loadNpmTasks('grunt-contrib-copy');
  grunt.loadNpmTasks('grunt-contrib-clean');

  grunt.registerTask('move', 'Moves the project to the build folder', ['copy', 'clean']);

};

1 个答案:

答案 0 :(得分:1)

你的路径错了。将build选项更改为:

build: {
  cwd: '.',
  src: ['src/**/*'],
  dest: './build',
  expand: true
}
  • ../build表示构建目录是在父目录中创建的(..是父目录)
  • src/**/*表示递归复制后代文件夹的所有文件和文件。
相关问题