postBuild.ts 870 B

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