Gruntjs 如何在排除根目录的同时压缩源文件夹?
我正在使用压缩我的部署包。我有以下配置:Gruntjs 如何在排除根目录的同时压缩源文件夹?,gruntjs,grunt-contrib-compress,Gruntjs,Grunt Contrib Compress,我正在使用压缩我的部署包。我有以下配置: // Zip up the distribution folder and give it a build name. The folder can then be uploaded to the Chrome Web Store. grunt.registerTask('compress-extension', 'compress the files which are ready to be uploaded to the Chrome Web S
// Zip up the distribution folder and give it a build name. The folder can then be uploaded to the Chrome Web Store.
grunt.registerTask('compress-extension', 'compress the files which are ready to be uploaded to the Chrome Web Store into a .zip', function () {
// There's no need to cleanup any old version because this will overwrite if it exists.
grunt.config.set('compress', {
dist: {
options: {
archive: 'Streamus v' + grunt.option('version') + '.zip'
},
files: [{
src: ['dist/**'],
dest: '',
}]
}
});
grunt.task.run('compress');
});
这将导致我希望避免的目录结构的一个附加级别。压缩后,结构如下所示:
'Streamus v0.xxx.zip' -> 'dist' -> '[sub directories]'
我只希望:
'Streamus v0.xxx.zip' -> '[sub directories]'
做这件事最简单的方法是什么?我可以在compress的“文件”配置部分表达这个愿望吗?也许是用扁平的?哦,我明白了。如果将“cwd”设置为要排除的文件夹,然后将“src”设置为考虑新的cwd,则它将按需要工作:
// Zip up the distribution folder and give it a build name. The folder can then be uploaded to the Chrome Web Store.
grunt.registerTask('compress-extension', 'compress the files which are ready to be uploaded to the Chrome Web Store into a .zip', function () {
// There's no need to cleanup any old version because this will overwrite if it exists.
grunt.config.set('compress', {
dist: {
options: {
archive: 'Streamus v' + grunt.option('version') + '.zip'
},
files: [{
src: ['**'],
dest: '',
cwd: 'dist/',
expand: true
}]
}
});
grunt.task.run('compress');
});