Skip to content

Commit 2e29be1

Browse files
committed
feat: add --fullBundleMode flag for vite dev
1 parent 29f0d18 commit 2e29be1

File tree

1 file changed

+92
-76
lines changed

1 file changed

+92
-76
lines changed

packages/vite/src/node/cli.ts

Lines changed: 92 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ interface GlobalCLIOptions {
3434
w?: boolean
3535
}
3636

37+
interface ExperimentalDevOptions {
38+
fullBundleMode?: boolean
39+
}
40+
3741
interface BuilderCLIOptions {
3842
app?: boolean
3943
}
@@ -176,93 +180,105 @@ cli
176180
'--force',
177181
`[boolean] force the optimizer to ignore the cache and re-bundle`,
178182
)
179-
.action(async (root: string, options: ServerOptions & GlobalCLIOptions) => {
180-
filterDuplicateOptions(options)
181-
// output structure is preserved even after bundling so require()
182-
// is ok here
183-
const { createServer } = await import('./server')
184-
try {
185-
const server = await createServer({
186-
root,
187-
base: options.base,
188-
mode: options.mode,
189-
configFile: options.config,
190-
configLoader: options.configLoader,
191-
logLevel: options.logLevel,
192-
clearScreen: options.clearScreen,
193-
server: cleanGlobalCLIOptions(options),
194-
forceOptimizeDeps: options.force,
195-
})
183+
.option('--fullBundleMode', `[boolean] use experimental full bundle mode`)
184+
.action(
185+
async (
186+
root: string,
187+
options: ServerOptions & ExperimentalDevOptions & GlobalCLIOptions,
188+
) => {
189+
filterDuplicateOptions(options)
190+
// output structure is preserved even after bundling so require()
191+
// is ok here
192+
const { createServer } = await import('./server')
193+
try {
194+
const server = await createServer({
195+
root,
196+
base: options.base,
197+
mode: options.mode,
198+
configFile: options.config,
199+
configLoader: options.configLoader,
200+
logLevel: options.logLevel,
201+
clearScreen: options.clearScreen,
202+
server: cleanGlobalCLIOptions(options),
203+
forceOptimizeDeps: options.force,
204+
experimental: {
205+
fullBundleMode: options.fullBundleMode,
206+
},
207+
})
196208

197-
if (!server.httpServer) {
198-
throw new Error('HTTP server not available')
199-
}
209+
if (!server.httpServer) {
210+
throw new Error('HTTP server not available')
211+
}
200212

201-
await server.listen()
213+
await server.listen()
202214

203-
const info = server.config.logger.info
215+
const info = server.config.logger.info
204216

205-
const modeString =
206-
options.mode && options.mode !== 'development'
207-
? ` ${colors.bgGreen(` ${colors.bold(options.mode)} `)}`
217+
const modeString =
218+
options.mode && options.mode !== 'development'
219+
? ` ${colors.bgGreen(` ${colors.bold(options.mode)} `)}`
220+
: ''
221+
const viteStartTime = global.__vite_start_time ?? false
222+
const startupDurationString = viteStartTime
223+
? colors.dim(
224+
`ready in ${colors.reset(
225+
colors.bold(Math.ceil(performance.now() - viteStartTime)),
226+
)} ms`,
227+
)
208228
: ''
209-
const viteStartTime = global.__vite_start_time ?? false
210-
const startupDurationString = viteStartTime
211-
? colors.dim(
212-
`ready in ${colors.reset(
213-
colors.bold(Math.ceil(performance.now() - viteStartTime)),
214-
)} ms`,
215-
)
216-
: ''
217-
const hasExistingLogs =
218-
process.stdout.bytesWritten > 0 || process.stderr.bytesWritten > 0
229+
const hasExistingLogs =
230+
process.stdout.bytesWritten > 0 || process.stderr.bytesWritten > 0
219231

220-
info(
221-
`\n ${colors.green(
222-
`${colors.bold('ROLLDOWN-VITE')} v${VERSION}`,
223-
)}${modeString} ${startupDurationString}\n`,
224-
{
225-
clear: !hasExistingLogs,
226-
},
227-
)
232+
info(
233+
`\n ${colors.green(
234+
`${colors.bold('ROLLDOWN-VITE')} v${VERSION}`,
235+
)}${modeString} ${startupDurationString}\n`,
236+
{
237+
clear: !hasExistingLogs,
238+
},
239+
)
228240

229-
server.printUrls()
230-
const customShortcuts: CLIShortcut<typeof server>[] = []
231-
if (profileSession) {
232-
customShortcuts.push({
233-
key: 'p',
234-
description: 'start/stop the profiler',
235-
async action(server) {
236-
if (profileSession) {
237-
await stopProfiler(server.config.logger.info)
238-
} else {
239-
const inspector = await import('node:inspector').then(
240-
(r) => r.default,
241-
)
242-
await new Promise<void>((res) => {
243-
profileSession = new inspector.Session()
244-
profileSession.connect()
245-
profileSession.post('Profiler.enable', () => {
246-
profileSession!.post('Profiler.start', () => {
247-
server.config.logger.info('Profiler started')
248-
res()
241+
server.printUrls()
242+
const customShortcuts: CLIShortcut<typeof server>[] = []
243+
if (profileSession) {
244+
customShortcuts.push({
245+
key: 'p',
246+
description: 'start/stop the profiler',
247+
async action(server) {
248+
if (profileSession) {
249+
await stopProfiler(server.config.logger.info)
250+
} else {
251+
const inspector = await import('node:inspector').then(
252+
(r) => r.default,
253+
)
254+
await new Promise<void>((res) => {
255+
profileSession = new inspector.Session()
256+
profileSession.connect()
257+
profileSession.post('Profiler.enable', () => {
258+
profileSession!.post('Profiler.start', () => {
259+
server.config.logger.info('Profiler started')
260+
res()
261+
})
249262
})
250263
})
251-
})
252-
}
264+
}
265+
},
266+
})
267+
}
268+
server.bindCLIShortcuts({ print: true, customShortcuts })
269+
} catch (e) {
270+
const logger = createLogger(options.logLevel)
271+
logger.error(
272+
colors.red(`error when starting dev server:\n${e.stack}`),
273+
{
274+
error: e,
253275
},
254-
})
276+
)
277+
stopProfiler(logger.info)
278+
process.exit(1)
255279
}
256-
server.bindCLIShortcuts({ print: true, customShortcuts })
257-
} catch (e) {
258-
const logger = createLogger(options.logLevel)
259-
logger.error(colors.red(`error when starting dev server:\n${e.stack}`), {
260-
error: e,
261-
})
262-
stopProfiler(logger.info)
263-
process.exit(1)
264-
}
265-
})
280+
},
281+
)
266282

267283
// build
268284
cli

0 commit comments

Comments
 (0)