Grunt Copy Flatten无法按预期工作 [英] Grunt Copy Flatten not working as expected

查看:93
本文介绍了Grunt Copy Flatten无法按预期工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  source / 
libraries /
d3.js
lodash.js
// etc

我将grunt-copy设置为如下:

  copy:{
main:{
files:[
{
src:[source / libraries / *。js],
dest:build /,
flatten:true
}

我期望它将输出压缩到构建中,这样我就可以拥有

  build / 
d3.js
// etc



<

  build / 
source /
libraries /
d3.js
// etc

什么给了?我是不是正确地使用扁平化?

解决方案

好吧,如果您只使用 flatten 因为你想让 source / libraries 中的所有内容进入 build ,我会建议实际使用 cwd (当前工作目录)选项。另一方面,如果您实际上在 source / libraries 中拥有子文件夹,那么您可能希望将 src 行设为 source / libraries / ** / *。js



无论如何,如果您可以使用 cwd 而是它看起来像这样:

  copy:{
main :{
files:[
{
src:[* .js],
dest:build /,
cwd:source / libraries /
}
]
}

对于另一种情况,也许这个? (注意展开选项设为 true

 main:{
files:[
{
src:[source / libraries / ** / *。js ],
dest:build /,
flatten:true,
expand:true
}
]
}
}


I have a directory structure as follows:

source/
    libraries/
        d3.js
        lodash.js
        //etc

I have grunt-copy setup as follows:

copy: {
  main: {
    files: [
      {
        src: ["source/libraries/*.js"], 
        dest: "build/", 
        flatten: true
      }

I expect it to flatten the output into build, so that I will have

build/
    d3.js
    //etc

Instead, I get a reproduction of the original directory structure in build:

build/
    source/
        libraries/
            d3.js
            //etc

What gives? Am I not using flatten properly?

解决方案

Well, if you're only using flatten because you want everything in source/libraries to go into build, I would suggest actually using the cwd (current working directory) option instead. If, on the other hand, you actually have subfolders in source/libraries then you probably want that src line to be source/libraries/**/*.js.

In any case, if you can use cwd instead it would look like this:

copy: {
  main: {
    files: [
      {
        src: ["*.js"],
        dest: "build/",
        cwd: "source/libraries/"
      }
    ]
  }

For the other case, maybe this? (Notice the expand option set to true)

copy: {
  main: {
    files: [
      {
        src: ["source/libraries/**/*.js"],
        dest: "build/",
        flatten: true,
        expand: true
      }
    ]
  }
}

这篇关于Grunt Copy Flatten无法按预期工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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