99} = require ( '@loki/core' ) ;
1010const { createChromeTarget } = require ( '@loki/target-chrome-core' ) ;
1111
12- function createChromeAppTarget ( {
13- baseUrl = 'http://localhost:6006' ,
14- chromeFlags = [ '--headless' , '--disable-gpu' , '--hide-scrollbars' ] ,
15- } ) {
16- let instance ;
17- let staticServer ;
12+ function getStaticServerConfig ( baseUrl ) {
1813 let staticServerPath ;
1914 let staticServerPort ;
2015
@@ -39,8 +34,27 @@ function createChromeAppTarget({
3934 }
4035 }
4136
37+ return {
38+ staticServerPath,
39+ staticServerPort,
40+ isLocalFile,
41+ chromeUrl,
42+ } ;
43+ }
44+
45+ function createChromeAppTarget ( {
46+ baseUrl = 'http://localhost:6006' ,
47+ useStaticServer = true ,
48+ chromeFlags = [ '--headless' , '--disable-gpu' , '--hide-scrollbars' ] ,
49+ } ) {
50+ let instance ;
51+ let staticServer ;
52+
53+ const { staticServerPath, staticServerPort, isLocalFile, chromeUrl } =
54+ getStaticServerConfig ( baseUrl ) ;
55+
4256 async function start ( options = { } ) {
43- if ( isLocalFile ) {
57+ if ( useStaticServer && isLocalFile ) {
4458 staticServer = createStaticServer ( staticServerPath ) ;
4559 staticServer . listen ( staticServerPort ) ;
4660 debug ( `Starting static file server at ${ chromeUrl } ` ) ;
@@ -66,7 +80,7 @@ function createChromeAppTarget({
6680 debug ( 'No chrome instance to kill' ) ;
6781 }
6882
69- if ( staticServer ) {
83+ if ( useStaticServer && staticServer ) {
7084 staticServer . close ( ) ;
7185 }
7286 }
@@ -86,7 +100,12 @@ function createChromeAppTarget({
86100 return client ;
87101 }
88102
89- return createChromeTarget ( start , stop , createNewDebuggerInstance , chromeUrl ) ;
103+ return createChromeTarget (
104+ start ,
105+ stop ,
106+ createNewDebuggerInstance ,
107+ useStaticServer ? chromeUrl : baseUrl
108+ ) ;
90109}
91110
92111module . exports = createChromeAppTarget ;
0 commit comments