Browse Source

fix: fix script preview no build

vben 4 năm trước cách đây
mục cha
commit
c2333f5d04
2 tập tin đã thay đổi với 13 bổ sung10 xóa
  1. 12 9
      build/script/build.ts
  2. 1 1
      build/script/preview.ts

+ 12 - 9
build/script/build.ts

@@ -1,6 +1,6 @@
 // #!/usr/bin/env node
 
-// import { sh } from 'tasksfile';
+import { sh } from 'tasksfile';
 
 import { argv } from 'yargs';
 import { runBuildConfig } from './buildConf';
@@ -8,22 +8,25 @@ import { runUpdateHtml } from './updateHtml';
 import { errorConsole, successConsole } from '../utils';
 import { startGzipStyle } from '../plugin/gzip/compress';
 
-export const runBuild = async () => {
+export const runBuild = async (preview = false) => {
   try {
     const argvList = argv._;
-    // let cmd = `cross-env NODE_ENV=production vite build`;
-    // // await run('cross-env', ['NODE_ENV=production', 'vite', 'build']);
-    // await sh(cmd, {
-    //   async: true,
-    //   nopipe: true,
-    // });
+    if (preview) {
+      let cmd = `cross-env NODE_ENV=production vite build`;
+      await sh(cmd, {
+        async: true,
+        nopipe: true,
+      });
+    }
 
     // Generate configuration file
     if (!argvList.includes('no-conf')) {
       await runBuildConfig();
     }
     await runUpdateHtml();
-    await startGzipStyle();
+    if (!preview) {
+      await startGzipStyle();
+    }
     successConsole('Vite Build successfully!');
   } catch (error) {
     errorConsole('Vite Build Error\n' + error);

+ 1 - 1
build/script/preview.ts

@@ -53,7 +53,7 @@ export const runPreview = async () => {
   });
   const { type } = await prompt;
   if (type === BUILD) {
-    await runBuild();
+    await runBuild(true);
   }
   startApp();
 };