postBuild.ts 908 字节
Newer Older
1 2
// #!/usr/bin/env node

V
vben 已提交
3
import { sh } from 'tasksfile';
V
vben 已提交
4

5 6
import { argv } from 'yargs';
import { runBuildConfig } from './buildConf';
7
// import { runUpdateHtml } from './updateHtml';
8
import { errorConsole, successConsole } from '../utils';
9
import { startGzipStyle } from '../vite/plugin/gzip/compress';
10

V
vben 已提交
11
export const runBuild = async (preview = false) => {
12 13
  try {
    const argvList = argv._;
V
vben 已提交
14
    if (preview) {
15
      let cmd = `cross-env NODE_ENV=production vite build`;
V
vben 已提交
16 17 18 19 20
      await sh(cmd, {
        async: true,
        nopipe: true,
      });
    }
21 22 23 24 25

    // Generate configuration file
    if (!argvList.includes('no-conf')) {
      await runBuildConfig();
    }
26
    // await runUpdateHtml();
V
vben 已提交
27 28 29
    if (!preview) {
      await startGzipStyle();
    }
30 31 32 33 34 35
    successConsole('Vite Build successfully!');
  } catch (error) {
    errorConsole('Vite Build Error\n' + error);
    process.exit(1);
  }
};
V
vben 已提交
36
runBuild();