简体   繁体   English

使用gulp-bower-normalize将所有文件复制到一个目录

[英]Use gulp-bower-normalize to copy all files to one directory

Can I use gulp-bower-normalize to copy different types of files from one directory to other one? 我可以使用gulp-bower-normalize将不同类型的文件从一个目录复制到另一目录吗?

I thought I can do that like this, but it just copies all fonts to their directories based on their file extensions. 我以为可以这样做,但是它只是根据文件扩展名将所有字体复制到其目录中。

"overrides": {
    "font-awesome": {
        "main": [
            "css/font-awesome.min.css",
            "fonts/*"
        ],
        "normalize": {
            "fonts": "fonts/*.*"
        }
    }
}

And removing the "fonts/*" from main will just copy the css. main删除"fonts/*"将仅复制css。

PS.: I know I can do that by gulp.src() and gulp.dest() but I was wondering about the "normalize-way". PS .:我知道我可以通过gulp.src()gulp.dest()来做到这一点,但是我想知道“规范化方式”。

//- gulpfile.js file
var bower = require('main-bower-files');
var bowerNorm = require('gulp-bower-normalize');
var DEST = './build/';

gulp.task('default', function () {
  return gulp.src(bower(), { base: './path/to/bower_components'})
    .pipe(bowerNorm({ flatten: true }))
    .pipe(gulp.dest(DEST));
});

//- bower.json file
"overrides": {
  "font-awesome": {
    "main": [
      "css/font-awesome.min.css",
      "fonts/*"
    ],
    "normalize": {
      "fonts": [ "*.eot", "*.svg", "*.ttf", "*.woff", "*.woff2" ]
    }
  }
}

The above should solve your problem. 以上应该可以解决您的问题。 When you use the normalize key under the dependencies key (in this case "font-awesome" ) the child keys ( "fonts" ) represent the folder names you're trying to create. 当您在依赖项键(在本例中为"font-awesome" )下使用normalize键时,子键( "fonts" )代表您要创建的文件夹名称。 The value or values for that key are the file types you want to put in that directory. 该键的值是您要放入该目录的文件类型。 So in the above solution we are saying, we would like to put "*.eot" , "*.svg" , "*.ttf" , "*.woff" , and "*.woff2" files in the "fonts" directory when we normalize our dependencies. 因此,在上述解决方案中,我们要说的是,我们希望将"*.eot""*.svg""*.ttf""*.woff""*.woff2"文件放在"fonts"规范化依赖项时的目录。

The result of the above code would be this: 以上代码的结果将是这样的:

build/
├── css/
│   └── font-awesome.min.css
└── fonts/
    ├── some-font-file.eot
    ├── some-font-file.svg
    ├── some-font-file.ttf
    ├── some-font-file.woff
    └── some-font-file.woff2

Let me know if I can clarify further. 让我知道是否可以进一步澄清。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM