0

我正在使用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 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]'

这样做最简单的方法是什么?我可以在压缩的“文件”配置部分表达这种愿望吗?也许用扁平化?

4

1 回答 1

0

我懂了。如果将“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');
});
于 2014-02-13T17:14:16.767 回答