grunt-init copyAndProcess损坏png文件

时间:2013-08-24 01:51:23

标签: gruntjs

我刚刚开始使用grunt-init。我有一切正常,除了我发现我的模板中的任何images / * .png文件在传输到目标文件夹时被破坏。

我怀疑init.copyAndProcess函数正在破坏它们(它们在Gimp中从模板文件夹而不是目标文件夹中打开)。

如何为模板中的文件子集复制而不是copyAndProcess?最好使用像'images / **'这样的模式来识别文件。

2 个答案:

答案 0 :(得分:1)

你实际上可以使用filesToCopy,因为你传递了一个noprocess哈希,告诉grunt-init它不应该处理的文件。

参考http://gruntjs.com/project-scaffolding#copying-files(grunt-init文档) 以及此提交的第73行的示例https://github.com/gruntjs/grunt-init-jquery/blob/ecf070d7469d610441458111bc05cd543ee5bbc0/template.js

答案 1 :(得分:0)

好吧,我会更喜欢更简洁的东西,类似于template.js中的内容:

var files = init.filesToCopy( props );
init.copyAndProcess( files, props );

但这有效:

var src_path = init.srcpath( 'images/' );
var dest_path = init.destpath( ) + '/images/';

// Copy the images folder this way to prevent corrupting the files
grunt.file.recurse( src_path, function( abspath, rootdir, subdir, filename ) {
    if ( subdir == undefined ) {
        var dest = dest_path + filename;
    } else {
        var dest = dest_path + subdir + '/' + filename;
    }
    grunt.file.copy( abspath, dest );
});