const FileManagerPlugin = require('filemanager-webpack-plugin')
const FStream = require('fs');
const myVersionFile_path = 'public/version.js';
const myOptDir = process.cwd().split(/[\\/]/).pop();
function setVersion(config) {
const version = new Date().getTime();
config.plugins[1].definitions['process.env'].VUE_APP_VERSION = version;
FStream.writeFileSync(myVersionFile_path, version)
}
console.log(process.env.VUE_APP_NODE_ENV === 'production', process.env.VUE_APP_NODE_ENV)
function migrateFile_and_compressDir(config) {
console.log(process.env.VUE_APP_NODE_ENV === 'production')
if (process.env.VUE_APP_NODE_ENV === 'production') {
/* 生成 复制版本号文件, 并压缩文件 */
let fileManagerPlugin = new FileManagerPlugin({
onEnd: {
copy: [{source: myVersionFile_path, destination: myOptDir},],
archive: [{source: myOptDir, destination: `${myOptDir}.zip`, format: 'zip',}]
}
});
config.plugins.push(fileManagerPlugin);
}
}
module.exports.my_configPackaging = function my_configPackaging(config) {
setVersion(config);
migrateFile_and_compressDir(config);
}
module.exports.myOptDir = myOptDir