1:如何使用webpack生成zip包
webpack插件filemanager-webpack-plugin(管理打包后的文件路径)
const FileManagerPlugin = require('filemanager-webpack-plugin'); // webpack zip
const srcFolder = path.resolve(__dirname, '../dist');
const zipFileName = utils.genName(); //zip的名字,一般使用活动名称+当前的时间
const zipFolderPath = path.resolve(__dirname, '../dist/zips/' + zipFileName);
const zipPkgPath = path.resolve(__dirname, '../dist/zips/' + zipFileName + '.zip');
webpackConfig.plugins.push(
new FileManagerPlugin({
onEnd: [
{
delete: [path.resolve(__dirname, '../dist/zips/*')]
},
{
mkdir: [zipFolderPath]
},
{
copy: [
{ source: srcFolder + '/htmls/*', destination: zipFolderPath + '/' + zipFileName + '/htmls' },
{ source: srcFolder + '/images/*', destination: zipFolderPath + '/' + zipFileName + '/images' },
{ source: srcFolder + '/static/*', destination: zipFolderPath + '/' + zipFileName + '/static' },
{
source: srcFolder + '/scripts/*.js',
destination: zipFolderPath + '/' + zipFileName + '/scripts'
},
{
source: srcFolder + '/styles/*.css',
destination: zipFolderPath + '/' + zipFileName + '/styles'
}
]
},
{
archive: [
{
source: zipFolderPath,
destination: zipPkgPath
}
]
},
{
delete: [zipFolderPath]
}
]
})
);
|