@@ -28,7 +28,7 @@ import clearTerminal from '../utilities/clear'
2828import readConfig_ from '../utilities/read-config'
2929
3030command (
31- 'serve [port][prod][aot][ sw]' ,
31+ 'serve [port][prod][sw]' ,
3232 'serve your application' ,
3333 args => {
3434 return args
@@ -54,7 +54,11 @@ function logServeCommandStart() {
5454 logInfo ( 'Launching Serve Command' )
5555}
5656
57- function serve ( isProdBuild = false , isServiceWorkerEnabled = false ) {
57+ export function serve (
58+ isProdBuild = false ,
59+ isServiceWorkerEnabled = false ,
60+ buildOnly = false
61+ ) {
5862 readConfig_ ( )
5963 . pipe (
6064 tap ( logServeCommandStart ) ,
@@ -175,52 +179,56 @@ function serve(isProdBuild = false, isServiceWorkerEnabled = false) {
175179 } )
176180 fuseSw . bundle ( 'ngsw-worker' ) . instructions ( ' > [ngsw-worker.js]' )
177181
178- fuseBrowser
179- . bundle ( 'vendor' )
180- . watch ( watchDir )
181- . instructions ( ` ~ ${ browserModule } ` )
182- . completed ( fn => {
183- isServiceWorkerEnabled &&
184- execSync (
185- `node_modules/.bin/ngsw-config .dist/public src/app/ngsw.json`
186- )
187- fuseServer
188- . bundle ( 'server' )
189- . instructions ( ` > [${ config . fusebox . server . serverModule } ]` )
190- . completed ( proc => {
191- prevServerProcess && prevServerProcess . kill ( )
192- clearTerminal ( )
193- proc . start ( )
194- prevServerProcess = proc
195- } )
196- fuseServer . run ( )
197- } )
182+ // tslint:disable:no-if-statement
183+ const vendor = fuseBrowser . bundle ( 'vendor' )
184+ if ( ! buildOnly ) vendor . watch ( watchDir )
185+ vendor . instructions ( ` ~ ${ browserModule } ` ) . completed ( fn => {
186+ isServiceWorkerEnabled &&
187+ execSync (
188+ `node_modules/.bin/ngsw-config .dist/public src/app/ngsw.json`
189+ )
190+ const serverBundle = fuseServer
191+ . bundle ( 'server' )
192+ . instructions ( ` > [${ config . fusebox . server . serverModule } ]` )
198193
199- fuseBrowser
200- . bundle ( 'app' )
201- . watch ( watchDir )
194+ if ( ! buildOnly ) {
195+ serverBundle . completed ( proc => {
196+ prevServerProcess && prevServerProcess . kill ( )
197+ clearTerminal ( )
198+ proc . start ( )
199+ prevServerProcess = proc
200+ } )
201+ }
202+ fuseServer . run ( )
203+ } )
204+
205+ const appBundle = fuseBrowser . bundle ( 'app' )
206+ if ( ! buildOnly ) appBundle . watch ( watchDir )
207+ appBundle
202208 . instructions ( ` !> [${ browserModule } ]` )
203209 . splitConfig ( { dest : '../js/modules' } )
204210
205211 logInfo ( 'Bundling your application, this may take some time...' )
206212
207213 renderSassDir ( )
208214
209- const sass = exec (
210- 'node_modules/.bin/node-sass --watch src/**/*.scss --output-style compressed --output src/**'
211- )
212- sass . on ( 'error' , err => {
213- console . log ( err )
214- process . exit ( 1 )
215- } )
216- sass . on ( 'message' , err => {
217- console . error ( err )
218- process . exit ( 1 )
219- } )
220- sass . stderr . on ( 'data' , err => {
221- console . log ( err )
222- process . exit ( 1 )
223- } )
215+ if ( ! buildOnly ) {
216+ const sass = exec (
217+ 'node_modules/.bin/node-sass --watch src/**/*.scss --output-style compressed --output src/**'
218+ )
219+ sass . on ( 'error' , err => {
220+ console . log ( err )
221+ process . exit ( 1 )
222+ } )
223+ sass . on ( 'message' , err => {
224+ console . error ( err )
225+ process . exit ( 1 )
226+ } )
227+ sass . stderr . on ( 'data' , err => {
228+ console . log ( err )
229+ process . exit ( 1 )
230+ } )
231+ }
224232
225233 copy ( resolve ( 'src/assets' ) , resolve ( '.dist/public/assets' ) )
226234 . then ( ( ) => fuseSw . run ( ) )
0 commit comments