vben
2020-10-26 2be166d6a1a0ef4c75eefbcc2054f0f86fad3c39
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// #!/usr/bin/env node
 
import { sh } from 'tasksfile';
 
import { argv } from 'yargs';
import { runBuildConfig } from './buildConf';
import { runUpdateHtml } from './updateHtml';
import { errorConsole, successConsole } from '../utils';
import { startGzipStyle } from '../plugin/gzip/compress';
 
export const runBuild = async (preview = false) => {
  try {
    const argvList = argv._;
    if (preview) {
      let cmd = `npm run build`;
      await sh(cmd, {
        async: true,
        nopipe: true,
      });
    }
 
    // Generate configuration file
    if (!argvList.includes('no-conf')) {
      await runBuildConfig();
    }
    await runUpdateHtml();
    if (!preview) {
      await startGzipStyle();
    }
    successConsole('Vite Build successfully!');
  } catch (error) {
    errorConsole('Vite Build Error\n' + error);
    process.exit(1);
  }
};
runBuild();