1
1
import ora from 'ora'
2
2
import path from 'path'
3
+ import fs from 'fs-extra'
3
4
import { slash } from '../utils/slash'
4
5
import { APP_PATH } from '../alias'
5
6
import { SiteConfig } from '../config'
@@ -71,7 +72,8 @@ export async function bundle(
71
72
} )
72
73
}
73
74
} ,
74
- minify : ssr ? false : ! process . env . DEBUG
75
+ // minify with esbuild in MPA mode (for CSS)
76
+ minify : ssr ? ( config . mpa ? 'esbuild' : false ) : ! process . env . DEBUG
75
77
}
76
78
} )
77
79
@@ -82,7 +84,7 @@ export async function bundle(
82
84
spinner . start ( 'building client + server bundles...' )
83
85
try {
84
86
; [ clientResult , serverResult ] = await ( Promise . all ( [
85
- build ( resolveViteConfig ( false ) ) ,
87
+ config . mpa ? null : build ( resolveViteConfig ( false ) ) ,
86
88
build ( resolveViteConfig ( true ) )
87
89
] ) as Promise < [ RollupOutput , RollupOutput ] > )
88
90
} catch ( e ) {
@@ -95,6 +97,23 @@ export async function bundle(
95
97
symbol : okMark
96
98
} )
97
99
100
+ if ( config . mpa ) {
101
+ // in MPA mode, we need to copy over the non-js asset files from the
102
+ // server build since there is no client-side build.
103
+ for ( const chunk of serverResult . output ) {
104
+ if ( ! chunk . fileName . endsWith ( '.js' ) ) {
105
+ const tempPath = path . resolve ( config . tempDir , chunk . fileName )
106
+ const outPath = path . resolve ( config . outDir , chunk . fileName )
107
+ await fs . copy ( tempPath , outPath )
108
+ }
109
+ }
110
+ // also copy over public dir
111
+ const publicDir = path . resolve ( config . srcDir , 'public' )
112
+ if ( fs . existsSync ( publicDir ) ) {
113
+ await fs . copy ( publicDir , config . outDir )
114
+ }
115
+ }
116
+
98
117
return [ clientResult , serverResult , pageToHashMap ]
99
118
}
100
119
0 commit comments