@@ -99,16 +99,21 @@ cli.command(
99
99
alias : 'f' ,
100
100
default : false ,
101
101
type : 'boolean' ,
102
- describe : 'force the optimizer to ignore the cache and re-bundle ' ,
102
+ describe : 'force the optimizer to ignore the cache and re-bundle' ,
103
103
} )
104
104
. option ( 'bind' , {
105
105
type : 'string' ,
106
106
default : '0.0.0.0' ,
107
107
describe : 'specify which IP addresses the server should listen on in remote mode' ,
108
108
} )
109
+ . option ( 'base' , {
110
+ type : 'string' ,
111
+ describe : 'base URL. Example: /demo/' ,
112
+ default : '/' ,
113
+ } )
109
114
. strict ( )
110
115
. help ( ) ,
111
- async ( { entry, theme, port : userPort , open, log, remote, tunnel, force, inspect, bind } ) => {
116
+ async ( { entry, theme, port : userPort , open, log, remote, tunnel, force, inspect, bind, base } ) => {
112
117
let server : ViteDevServer | undefined
113
118
let port = 3030
114
119
@@ -126,7 +131,7 @@ cli.command(
126
131
async function initServer ( ) {
127
132
if ( server )
128
133
await server . close ( )
129
- const options = await resolveOptions ( { entry, remote, theme, inspect } , 'dev' )
134
+ const options = await resolveOptions ( { entry, remote, theme, inspect, base } , 'dev' )
130
135
const host = remote !== undefined ? bind : 'localhost'
131
136
port = userPort || await getPort ( {
132
137
port : 3030 ,
@@ -150,6 +155,7 @@ cli.command(
150
155
force,
151
156
} ,
152
157
logLevel : log as LogLevel ,
158
+ base,
153
159
} ,
154
160
{
155
161
async loadData ( loadedSource ) {
@@ -201,7 +207,7 @@ cli.command(
201
207
if ( remote )
202
208
publicIp = await import ( 'public-ip' ) . then ( r => r . publicIpv4 ( ) )
203
209
204
- lastRemoteUrl = printInfo ( options , port , remote , tunnelUrl , publicIp )
210
+ lastRemoteUrl = printInfo ( options , port , base , remote , tunnelUrl , publicIp )
205
211
}
206
212
207
213
async function openTunnel ( port : number ) {
@@ -225,7 +231,7 @@ cli.command(
225
231
name : 'o' ,
226
232
fullname : 'open' ,
227
233
action ( ) {
228
- openBrowser ( `http://localhost:${ port } ` )
234
+ openBrowser ( `http://localhost:${ port } ${ base } ` )
229
235
} ,
230
236
} ,
231
237
{
@@ -334,7 +340,7 @@ cli.command(
334
340
} )
335
341
. option ( 'base' , {
336
342
type : 'string' ,
337
- describe : 'output base' ,
343
+ describe : 'output base. Example: /demo/ ' ,
338
344
} )
339
345
. option ( 'download' , {
340
346
alias : 'd' ,
@@ -353,7 +359,7 @@ cli.command(
353
359
const { build } = await import ( './commands/build' )
354
360
355
361
for ( const entryFile of entry as unknown as string [ ] ) {
356
- const options = await resolveOptions ( { entry : entryFile , theme, inspect, download } , 'build' )
362
+ const options = await resolveOptions ( { entry : entryFile , theme, inspect, download, base } , 'build' )
357
363
358
364
printInfo ( options )
359
365
await build (
@@ -621,10 +627,13 @@ function exportOptions<T>(args: Argv<T>) {
621
627
function printInfo (
622
628
options : ResolvedSlidevOptions ,
623
629
port ?: number ,
630
+ base ?: string ,
624
631
remote ?: string ,
625
632
tunnelUrl ?: string ,
626
633
publicIp ?: string ,
627
634
) {
635
+ const baseUrl = port && `http://localhost:${ bold ( port + ( base ?. slice ( 0 , - 1 ) || '' ) ) } `
636
+
628
637
console . log ( )
629
638
console . log ( )
630
639
console . log ( ` ${ cyan ( '●' ) + blue ( '■' ) + yellow ( '▲' ) } ` )
@@ -637,22 +646,22 @@ function printInfo(
637
646
console . log ( dim ( ' css engine ' ) + blue ( 'unocss' ) )
638
647
console . log ( dim ( ' entry ' ) + dim ( path . normalize ( path . dirname ( options . entry ) ) + path . sep ) + path . basename ( options . entry ) )
639
648
640
- if ( port ) {
649
+ if ( baseUrl ) {
641
650
const query = remote ? `?password=${ remote } ` : ''
642
651
const presenterPath = `${ options . data . config . routerMode === 'hash' ? '/#/' : '/' } presenter/${ query } `
643
652
const entryPath = `${ options . data . config . routerMode === 'hash' ? '/#/' : '/' } entry${ query } /`
644
653
const overviewPath = `${ options . data . config . routerMode === 'hash' ? '/#/' : '/' } overview${ query } /`
645
654
console . log ( )
646
- console . log ( `${ dim ( ' public slide show ' ) } > ${ cyan ( `http://localhost: ${ bold ( port ) } /` ) } ` )
655
+ console . log ( `${ dim ( ' public slide show ' ) } > ${ cyan ( `${ baseUrl } /` ) } ` )
647
656
if ( query )
648
- console . log ( `${ dim ( ' private slide show ' ) } > ${ cyan ( `http://localhost: ${ bold ( port ) } /${ query } ` ) } ` )
657
+ console . log ( `${ dim ( ' private slide show ' ) } > ${ cyan ( `${ baseUrl } /${ query } ` ) } ` )
649
658
if ( options . utils . define . __SLIDEV_FEATURE_PRESENTER__ )
650
- console . log ( `${ dim ( ' presenter mode ' ) } > ${ blue ( `http://localhost: ${ bold ( port ) } ${ presenterPath } ` ) } ` )
651
- console . log ( `${ dim ( ' slides overview ' ) } > ${ blue ( `http://localhost: ${ bold ( port ) } ${ overviewPath } ` ) } ` )
659
+ console . log ( `${ dim ( ' presenter mode ' ) } > ${ blue ( `${ baseUrl } ${ presenterPath } ` ) } ` )
660
+ console . log ( `${ dim ( ' slides overview ' ) } > ${ blue ( `${ baseUrl } ${ overviewPath } ` ) } ` )
652
661
if ( options . utils . define . __SLIDEV_FEATURE_BROWSER_EXPORTER__ )
653
- console . log ( `${ dim ( ' export slides' ) } > ${ blue ( `http://localhost: ${ bold ( port ) } /export/` ) } ` )
662
+ console . log ( `${ dim ( ' export slides' ) } > ${ blue ( `${ baseUrl } /export/` ) } ` )
654
663
if ( options . inspect )
655
- console . log ( `${ dim ( ' vite inspector' ) } > ${ yellow ( `http://localhost: ${ bold ( port ) } /__inspect/` ) } ` )
664
+ console . log ( `${ dim ( ' vite inspector' ) } > ${ yellow ( `${ baseUrl } /__inspect/` ) } ` )
656
665
657
666
let lastRemoteUrl = ''
658
667
0 commit comments