compressing the compressed folder node

problem found

Project on-line

After a packed period (ie, the familiar npm run build), compression (by compression tool pressed into .zipthe package), on-line (on-line compressed packet to the staff), and finally, we have found the optimization of space, ha ha.

what? Also part of the project on-line manual? Use compressed way? Not to use automated deployment?

Excuse me, Excuse me.

Protagonist debut

Looking for a bit and found a useful, convenient package compressing, support compressed folders, support for zipcompression.

Compact Now

Compression program can do, why should their own to manually compress, then, there is the following story.

const path = require("path");
const fs = require("fs");
const chalk = require("chalk");
// 这个是主角
const compressing = require("compressing");
const dayjs = require("dayjs");

const resolve = dir => path.join(__dirname, "..", dir);
const publishPath = resolve("publish");
const zipName = (() => `publish/fzApp ${dayjs().format("YYYYMMDD_HHmm")}.zip`)();

// 判断是否存在当前publish路径,没有就新增
if (!fs.existsSync(publishPath)) {
    fs.mkdirSync(publishPath);
}

compressing.zip
    .compressDir(resolve("dist/"), resolve(zipName))
    .then(() => {
        console.log(chalk.yellow(`Tip: 文件压缩成功,已压缩至【${resolve(zipName)}】`));
    })
    .catch(err => {
        console.log(chalk.red("Tip: 压缩报错"));
        console.error(err);
    });

problem solved

Automatic compression on this point, the problem is solved.

Then, after the process on the line becomes:
pack ( npm run build && npm run zip), on-line (sending zipcompressed packet on line art).

Guess you like

Origin www.cnblogs.com/xieqian/p/10973324.html