@@ -4,7 +4,7 @@ import { findClosestOpenPort } from '@ionic/utils-network';
4
4
5
5
import { CommandMetadata , ReactServeOptions , ServeDetails } from '../../../definitions' ;
6
6
import { input , strong } from '../../color' ;
7
- import { BIND_ALL_ADDRESS , LOCAL_ADDRESSES , SERVE_SCRIPT , ServeCLI , ServeRunner , ServeRunnerDeps } from '../../serve' ;
7
+ import { BIND_ALL_ADDRESS , DEFAULT_ADDRESS , LOCAL_ADDRESSES , SERVE_SCRIPT , ServeCLI , ServeRunner , ServeRunnerDeps } from '../../serve' ;
8
8
9
9
export class ReactServeRunner extends ServeRunner < ReactServeOptions > {
10
10
constructor ( protected readonly e : ServeRunnerDeps ) {
@@ -69,7 +69,7 @@ export class ReactServeRunner extends ServeRunner<ReactServeOptions> {
69
69
}
70
70
71
71
async serveProject ( options : ReactServeOptions ) : Promise < ServeDetails > {
72
- const [ externalIP , availableInterfaces ] = await this . selectExternalIP ( options ) ;
72
+ const [ externalIP , availableInterfaces ] = await this . selectExternalIP ( options ) ;
73
73
74
74
const port = options . port = await findClosestOpenPort ( options . port ) ;
75
75
@@ -137,21 +137,25 @@ export class ReactServeCLI extends ServeCLI<ReactServeOptions> {
137
137
if ( this . resolvedProgram === this . program ) {
138
138
return [ 'start' ] ;
139
139
} else {
140
- const [ , ...pkgArgs ] = await pkgManagerArgs ( this . e . config . get ( 'npmClient' ) , { command : 'run' , script : this . script } ) ;
140
+ const [ , ...pkgArgs ] = await pkgManagerArgs ( this . e . config . get ( 'npmClient' ) , { command : 'run' , script : this . script } ) ;
141
141
return pkgArgs ;
142
142
}
143
143
}
144
144
145
145
protected async buildEnvVars ( options : ReactServeOptions ) : Promise < NodeJS . ProcessEnv > {
146
146
const envVars : NodeJS . ProcessEnv = { } ;
147
147
148
- if ( options . browser ) {
149
- envVars . BROWSER = options . browser ;
150
- }
151
- if ( options . open !== true ) {
152
- envVars . BROWSER = 'none' ;
148
+ envVars . BROWSER = 'none' ;
149
+
150
+ /*
151
+ By default, CRA binds to localhost,
152
+ but if you specify it, it puts a warning in the console,
153
+ so don't set the HOST if the address is set to 'localhost'
154
+ */
155
+ if ( options . address !== DEFAULT_ADDRESS ) {
156
+ envVars . HOST = options . address ;
153
157
}
154
- envVars . HOST = options . address ;
158
+
155
159
envVars . PORT = String ( options . port ) ;
156
160
envVars . HTTPS = ( options . https === true ) ? 'true' : 'false' ;
157
161
envVars . CI = ( options . ci === true ) ? 'true' : 'false' ;
0 commit comments