【问题标题】:grunt copy task is misbehavinggrunt 复制任务行为不端
【发布时间】:2014-05-09 02:40:44
【问题描述】:

更新

部分问题是front/styles 包含css 和scss 文件。我只想复制css文件。

原创

所以来自grunt-contrib-copycopy 任务应该做一件事。从front/styles复制所有*.css文件并将它们移动到front/build/styles

copy: {
  css: {
    files: {
      src: ['front/styles/*.css'],
      dest: 'front/build/styles/',
      filter: 'isFile'
    }
  }
},

我运行grunt copy 并创建一个名为dest 的文件夹,与front 文件夹处于同一级别。我进入front/build/styles,那里什么都没有。这是一项相对容易配置的任务,过去曾这样做过,但这让我感到困惑。

我在配置中忽略了什么?

【问题讨论】:

  • 试试 src: ['front/styles/*']
  • 啊,但是里面有scss文件。可以通过将样式拆分为 css 和 scss 来解决,但真的很想避免这种情况。

标签: javascript gruntjs grunt-contrib-copy


【解决方案1】:

试一试:

copy: {
  css: {
    files: {
      cwd: 'front/styles/',
      src: '*.css',
      dest: 'front/build/styles/',
      filter: 'isFile'
    }
  }
},

【讨论】:

  • 此配置现在创建两个文件夹 dest 和之前一样,cwd 是与 front 文件夹相同级别的新文件夹。两者都是空的。为什么它会忽略我输入的值,将任务配置参数创建为空目录?
  • 愚蠢的问题,但是您是在复制任务之前还是之后运行指南针?也许 .css 文件在该过程的一部分中还不存在?我们能看到更多的 grunt 文件吗?
【解决方案2】:

想通了。

copy: {
  css: {
    files: [
      {
        expand: true,
        flatten: true,
        src: 'front/styles/*.css',
        dest: 'front/build/styles/'
      }
    ]
  }
},

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-02-13
    • 2015-07-05
    • 1970-01-01
    • 2013-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-06
    相关资源
    最近更新 更多